X-Git-Url: http://git.tuebingen.mpg.de/?p=adu.git;a=blobdiff_plain;f=adu.h;h=775af7faef3c85bfc3890e87426b044f161a552b;hp=ee992acc8aff5b667f81a59d0b694552c8ab3f92;hb=f732616f8be8b2c8b4137108faa25eeaccb77499;hpb=a4cf08e8062d1d73c343a628563acf4d9f454742 diff --git a/adu.h b/adu.h index ee992ac..775af7f 100644 --- a/adu.h +++ b/adu.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 1997-2008 Andre Noll + * Copyright (C) 2008 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -23,11 +23,9 @@ #include /* needed by create_pf_socket */ #include #include +#include #include "gcc-compat.h" -/** used in various contexts */ -#define MAXLINE 255 - /** compute the minimum of \a a and \a b */ #define MIN(a,b) ((a) < (b) ? (a) : (b)) /** compute the maximum of \a a and \a b */ @@ -96,69 +94,6 @@ #define EMERG_LOG(...) #endif /** \endcond */ - -/** - * define a standard log function that always writes to stderr - * - * \param loglevel_barrier If the loglevel of the current message - * is less than that, the message is going to be ignored. - * - */ -#define INIT_STDERR_LOGGING(loglevel_barrier) \ - __printf_2_3 void __log(int ll, const char* fmt,...) \ - { \ - va_list argp; \ - if (ll < loglevel_barrier) \ - return; \ - va_start(argp, fmt); \ - vfprintf(stderr, fmt, argp); \ - va_end(argp); \ - } - -/** version text used by various commands if -V switch was given */ -#define VERSION_TEXT(prefix) "para_" prefix " " PACKAGE_VERSION " (" CODENAME ")" "\n" \ - "Copyright (C) 2008 Andre Noll\n" \ - "This is free software with ABSOLUTELY NO WARRANTY." \ - " See COPYING for details.\n" \ - "Written by Andre Noll.\n" \ - "Report bugs to .\n" - -/** print out \p VERSION_TEXT and exit if version flag was given */ -#define HANDLE_VERSION_FLAG(_prefix, _args_info_struct) \ - if (_args_info_struct.version_given) { \ - printf("%s", VERSION_TEXT(_prefix)); \ - exit(EXIT_SUCCESS); \ - } -/** sent by para_server for commands that expect a data file */ -#define AWAITING_DATA_MSG "\nAwaiting Data." -/** sent by para_server if authentication was successful */ -#define PROCEED_MSG "\nProceed.\n" -/** length of the \p PROCEED_MSG string */ -#define PROCEED_MSG_LEN strlen(PROCEED_MSG) -/** sent by para_client to indicate the end of the command line */ -#define EOC_MSG "\nEnd of Command." -/** sent by para_client, followed by the decrypted challenge number */ -#define CHALLENGE_RESPONSE_MSG "challenge_response:" - -/* exec */ -int para_exec_cmdline_pid(pid_t *pid, const char *cmdline, int *fds); - -/* time */ -int tv_diff(const struct timeval *b, const struct timeval *a, struct timeval *diff); -long unsigned tv2ms(const struct timeval*); -void d2tv(double, struct timeval*); -void tv_add(const struct timeval*, const struct timeval *, struct timeval *); -void tv_scale(const unsigned long, const struct timeval *, struct timeval *); -void tv_divide(const unsigned long divisor, const struct timeval *tv, - struct timeval *result); -int tv_convex_combination(const long a, const struct timeval *tv1, - const long b, const struct timeval *tv2, - struct timeval *result); -void ms2tv(const long unsigned n, struct timeval *tv); -void compute_chunk_time(long unsigned chunk_num, - struct timeval *chunk_tv, struct timeval *stream_start, - struct timeval *result); - __printf_2_3 void __log(int, const char*, ...); /** @@ -172,7 +107,7 @@ __printf_2_3 void __log(int, const char*, ...); { \ int n; \ size_t size = 100; \ - p = para_malloc(size); \ + p = adu_malloc(size); \ while (1) { \ va_list ap; \ /* Try to print in the allocated space. */ \ @@ -187,39 +122,6 @@ __printf_2_3 void __log(int, const char*, ...); size = n + 1; /* precisely what is needed */ \ else /* glibc 2.0 */ \ size *= 2; /* twice the old size */ \ - p = para_realloc(p, size); \ + p = adu_realloc(p, size); \ } \ } - -/** - * Return a random non-negative integer in an interval. - * - * \param max Determines maximal possible return value. - * - * \return An integer between zero and \p max - 1, inclusively. - */ -static inline long int para_random(unsigned max) -{ - return ((max + 0.0) * (random() / (RAND_MAX + 1.0))); -} - -/** Round up x to a multiple of y */ -#define ROUND_UP(x, y) (((x) + ((y) - 1) / (y)) * (y)) - -/** Get the size of an array */ -#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) - -/** - * Wrapper for isspace. - * NetBSD needs this. - */ -/* - * The values should be cast to an unsigned char first, then to int. - * Why? Because the isdigit (as do all other is/to functions/macros) - * expect a number from 0 upto and including 255 as their (int) argument. - * Because char is signed on most systems, casting it to int immediately - * gives the functions an argument between -128 and 127 (inclusive), - * which they will use as an array index, and which will thus fail - * horribly for characters which have their most significant bit set. - */ -#define para_isspace(c) isspace((int)(unsigned char)(c))