diff options
| author | Greg Hudson <ghudson@mit.edu> | 2009-11-14 18:56:43 +0000 |
|---|---|---|
| committer | Greg Hudson <ghudson@mit.edu> | 2009-11-14 18:56:43 +0000 |
| commit | be4e9d973c2717872663010c9c02f8bc75cb18a5 (patch) | |
| tree | 7e9080437aebd7807d08a27ac454a3144ef5ec1d /src/include/k5-platform.h | |
| parent | 8852050c9361822bd182634ee2ce833d4d9f14e8 (diff) | |
| download | krb5-be4e9d973c2717872663010c9c02f8bc75cb18a5.tar.gz krb5-be4e9d973c2717872663010c9c02f8bc75cb18a5.tar.xz krb5-be4e9d973c2717872663010c9c02f8bc75cb18a5.zip | |
Reindent include directory, reformatting prototypes as necessary.
Exclude include/gssrpc due to its Sun origin and k5-platform.h due to
macros too hairy for emacs c-mode to handle.
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@23180 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/include/k5-platform.h')
| -rw-r--r-- | src/include/k5-platform.h | 285 |
1 files changed, 143 insertions, 142 deletions
diff --git a/src/include/k5-platform.h b/src/include/k5-platform.h index d4d05aee1..7c1c57d70 100644 --- a/src/include/k5-platform.h +++ b/src/include/k5-platform.h @@ -1,3 +1,4 @@ +/* -*- mode: c; indent-tabs-mode: nil -*- */ /* * k5-platform.h * @@ -16,7 +17,7 @@ * this permission notice appear in supporting documentation, and that * the name of M.I.T. not be used in advertising or publicity pertaining * to distribution of the software without specific, written prior - * permission. Furthermore if you modify this software you must label + * permission. Furthermore if you modify this software you must label * your software as modified software and not distribute it in such a * fashion that it might be confused with the original M.I.T. software. * M.I.T. makes no representations about the suitability of @@ -209,52 +210,52 @@ # include "k5-thread.h" typedef struct { k5_once_t once; int error, did_run; void (*fn)(void); } k5_init_t; # ifdef USE_LINKER_INIT_OPTION -# define MAYBE_DUMMY_INIT(NAME) \ - void JOIN__2(NAME, auxinit) () { } +# define MAYBE_DUMMY_INIT(NAME) \ + void JOIN__2(NAME, auxinit) () { } # else # define MAYBE_DUMMY_INIT(NAME) # endif # ifdef __GNUC__ /* Do it in macro form so we get the file/line of the invocation if the assertion fails. */ -# define k5_call_init_function(I) \ - (__extension__ ({ \ - k5_init_t *k5int_i = (I); \ - int k5int_err = k5_once(&k5int_i->once, k5int_i->fn); \ - (k5int_err \ - ? k5int_err \ - : (assert(k5int_i->did_run != 0), k5int_i->error)); \ - })) +# define k5_call_init_function(I) \ + (__extension__ ({ \ + k5_init_t *k5int_i = (I); \ + int k5int_err = k5_once(&k5int_i->once, k5int_i->fn); \ + (k5int_err \ + ? k5int_err \ + : (assert(k5int_i->did_run != 0), k5int_i->error)); \ + })) # define MAYBE_DEFINE_CALLINIT_FUNCTION # else -# define MAYBE_DEFINE_CALLINIT_FUNCTION \ - static inline int k5_call_init_function(k5_init_t *i) \ - { \ - int err; \ - err = k5_once(&i->once, i->fn); \ - if (err) \ - return err; \ - assert (i->did_run != 0); \ - return i->error; \ - } +# define MAYBE_DEFINE_CALLINIT_FUNCTION \ + static inline int k5_call_init_function(k5_init_t *i) \ + { \ + int err; \ + err = k5_once(&i->once, i->fn); \ + if (err) \ + return err; \ + assert (i->did_run != 0); \ + return i->error; \ + } # endif -# define MAKE_INIT_FUNCTION(NAME) \ - static int NAME(void); \ - MAYBE_DUMMY_INIT(NAME) \ - /* forward declaration for use in initializer */ \ - static void JOIN__2(NAME, aux) (void); \ - static k5_init_t JOIN__2(NAME, once) = \ - { K5_ONCE_INIT, 0, 0, JOIN__2(NAME, aux) }; \ - MAYBE_DEFINE_CALLINIT_FUNCTION \ - static void JOIN__2(NAME, aux) (void) \ - { \ - JOIN__2(NAME, once).did_run = 1; \ - JOIN__2(NAME, once).error = NAME(); \ - } \ - /* so ';' following macro use won't get error */ \ - static int NAME(void) -# define CALL_INIT_FUNCTION(NAME) \ - k5_call_init_function(& JOIN__2(NAME, once)) +# define MAKE_INIT_FUNCTION(NAME) \ + static int NAME(void); \ + MAYBE_DUMMY_INIT(NAME) \ + /* forward declaration for use in initializer */ \ + static void JOIN__2(NAME, aux) (void); \ + static k5_init_t JOIN__2(NAME, once) = \ + { K5_ONCE_INIT, 0, 0, JOIN__2(NAME, aux) }; \ + MAYBE_DEFINE_CALLINIT_FUNCTION \ + static void JOIN__2(NAME, aux) (void) \ + { \ + JOIN__2(NAME, once).did_run = 1; \ + JOIN__2(NAME, once).error = NAME(); \ + } \ + /* so ';' following macro use won't get error */ \ + static int NAME(void) +# define CALL_INIT_FUNCTION(NAME) \ + k5_call_init_function(& JOIN__2(NAME, once)) /* This should be called in finalization only, so we shouldn't have multiple active threads mucking around in our library at this point. So ignore the once_t object and just look at the flag. @@ -264,10 +265,10 @@ typedef struct { k5_once_t once; int error, did_run; void (*fn)(void); } k5_init application code should already be coordinating things such that the library code is not in use by this point, and memory synchronization will be needed there. */ -# define INITIALIZER_RAN(NAME) \ - (JOIN__2(NAME, once).did_run && JOIN__2(NAME, once).error == 0) +# define INITIALIZER_RAN(NAME) \ + (JOIN__2(NAME, once).did_run && JOIN__2(NAME, once).error == 0) -# define PROGRAM_EXITING() (0) +# define PROGRAM_EXITING() (0) #elif defined(__GNUC__) && !defined(_WIN32) && defined(CONSTRUCTOR_ATTR_WORKS) @@ -275,63 +276,63 @@ typedef struct { k5_once_t once; int error, did_run; void (*fn)(void); } k5_init # ifdef USE_LINKER_INIT_OPTION /* Both gcc and linker option?? Favor gcc. */ -# define MAYBE_DUMMY_INIT(NAME) \ - void JOIN__2(NAME, auxinit) () { } +# define MAYBE_DUMMY_INIT(NAME) \ + void JOIN__2(NAME, auxinit) () { } # else # define MAYBE_DUMMY_INIT(NAME) # endif typedef struct { int error; unsigned char did_run; } k5_init_t; -# define MAKE_INIT_FUNCTION(NAME) \ - MAYBE_DUMMY_INIT(NAME) \ - static k5_init_t JOIN__2(NAME, ran) \ - = { 0, 2 }; \ - static void JOIN__2(NAME, aux)(void) \ - __attribute__((constructor)); \ - static int NAME(void); \ - static void JOIN__2(NAME, aux)(void) \ - { \ - JOIN__2(NAME, ran).error = NAME(); \ - JOIN__2(NAME, ran).did_run = 3; \ - } \ - static int NAME(void) -# define CALL_INIT_FUNCTION(NAME) \ - (JOIN__2(NAME, ran).did_run == 3 \ - ? JOIN__2(NAME, ran).error \ - : (abort(),0)) -# define INITIALIZER_RAN(NAME) (JOIN__2(NAME,ran).did_run == 3 && JOIN__2(NAME, ran).error == 0) - -# define PROGRAM_EXITING() (0) +# define MAKE_INIT_FUNCTION(NAME) \ + MAYBE_DUMMY_INIT(NAME) \ + static k5_init_t JOIN__2(NAME, ran) \ + = { 0, 2 }; \ + static void JOIN__2(NAME, aux)(void) \ + __attribute__((constructor)); \ + static int NAME(void); \ + static void JOIN__2(NAME, aux)(void) \ + { \ + JOIN__2(NAME, ran).error = NAME(); \ + JOIN__2(NAME, ran).did_run = 3; \ + } \ + static int NAME(void) +# define CALL_INIT_FUNCTION(NAME) \ + (JOIN__2(NAME, ran).did_run == 3 \ + ? JOIN__2(NAME, ran).error \ + : (abort(),0)) +# define INITIALIZER_RAN(NAME) (JOIN__2(NAME,ran).did_run == 3 && JOIN__2(NAME, ran).error == 0) + +# define PROGRAM_EXITING() (0) #elif defined(USE_LINKER_INIT_OPTION) || defined(_WIN32) /* Run initializer at load time, via linker magic, or in the case of WIN32, win_glue.c hard-coded knowledge. */ typedef struct { int error; unsigned char did_run; } k5_init_t; -# define MAKE_INIT_FUNCTION(NAME) \ - static k5_init_t JOIN__2(NAME, ran) \ - = { 0, 2 }; \ - static int NAME(void); \ - void JOIN__2(NAME, auxinit)() \ - { \ - JOIN__2(NAME, ran).error = NAME(); \ - JOIN__2(NAME, ran).did_run = 3; \ - } \ - static int NAME(void) -# define CALL_INIT_FUNCTION(NAME) \ - (JOIN__2(NAME, ran).did_run == 3 \ - ? JOIN__2(NAME, ran).error \ - : (abort(),0)) -# define INITIALIZER_RAN(NAME) \ - (JOIN__2(NAME, ran).error == 0) - -# define PROGRAM_EXITING() (0) +# define MAKE_INIT_FUNCTION(NAME) \ + static k5_init_t JOIN__2(NAME, ran) \ + = { 0, 2 }; \ + static int NAME(void); \ + void JOIN__2(NAME, auxinit)() \ + { \ + JOIN__2(NAME, ran).error = NAME(); \ + JOIN__2(NAME, ran).did_run = 3; \ + } \ + static int NAME(void) +# define CALL_INIT_FUNCTION(NAME) \ + (JOIN__2(NAME, ran).did_run == 3 \ + ? JOIN__2(NAME, ran).error \ + : (abort(),0)) +# define INITIALIZER_RAN(NAME) \ + (JOIN__2(NAME, ran).error == 0) + +# define PROGRAM_EXITING() (0) #else # error "Don't know how to do load-time initializers for this configuration." -# define PROGRAM_EXITING() (0) +# define PROGRAM_EXITING() (0) #endif @@ -345,29 +346,29 @@ typedef struct { int error; unsigned char did_run; } k5_init_t; # ifdef __hpux /* On HP-UX, we need this auxiliary function. At dynamic load or - unload time (but *not* program startup and termination for - link-time specified libraries), the linker-indicated function - is called with a handle on the library and a flag indicating - whether it's being loaded or unloaded. + unload time (but *not* program startup and termination for + link-time specified libraries), the linker-indicated function + is called with a handle on the library and a flag indicating + whether it's being loaded or unloaded. - The "real" fini function doesn't need to be exported, so - declare it static. + The "real" fini function doesn't need to be exported, so + declare it static. - As usual, the final declaration is just for syntactic - convenience, so the top-level invocation of this macro can be - followed by a semicolon. */ + As usual, the final declaration is just for syntactic + convenience, so the top-level invocation of this macro can be + followed by a semicolon. */ # include <dl.h> -# define MAKE_FINI_FUNCTION(NAME) \ - static void NAME(void); \ - void JOIN__2(NAME, auxfini)(shl_t, int); /* silence gcc warnings */ \ - void JOIN__2(NAME, auxfini)(shl_t h, int l) { if (!l) NAME(); } \ - static void NAME(void) +# define MAKE_FINI_FUNCTION(NAME) \ + static void NAME(void); \ + void JOIN__2(NAME, auxfini)(shl_t, int); /* silence gcc warnings */ \ + void JOIN__2(NAME, auxfini)(shl_t h, int l) { if (!l) NAME(); } \ + static void NAME(void) # else /* not hpux */ -# define MAKE_FINI_FUNCTION(NAME) \ - void NAME(void) +# define MAKE_FINI_FUNCTION(NAME) \ + void NAME(void) # endif @@ -378,8 +379,8 @@ typedef struct { int error; unsigned char did_run; } k5_init_t; function attribute that makes use of the same facility as C++. XXX How do we know if the C++ support actually works? */ -# define MAKE_FINI_FUNCTION(NAME) \ - static void NAME(void) __attribute__((destructor)) +# define MAKE_FINI_FUNCTION(NAME) \ + static void NAME(void) __attribute__((destructor)) #elif !defined(SHARED) @@ -388,8 +389,8 @@ typedef struct { int error; unsigned char did_run; } k5_init_t; The code will still define the function, but we won't do anything with it. Annoying: This may generate unused-function warnings. */ -# define MAKE_FINI_FUNCTION(NAME) \ - static void NAME(void) +# define MAKE_FINI_FUNCTION(NAME) \ + static void NAME(void) #else @@ -505,10 +506,10 @@ typedef struct { int error; unsigned char did_run; } k5_init_t; on most of our platforms except Windows, where we're not using GCC. */ #ifdef __GNUC__ -# define PUT(SIZE,PTR,VAL) (((struct { uint##SIZE##_t i; } __attribute__((packed)) *)(PTR))->i = (VAL)) -# define GET(SIZE,PTR) (((const struct { uint##SIZE##_t i; } __attribute__((packed)) *)(PTR))->i) -# define PUTSWAPPED(SIZE,PTR,VAL) PUT(SIZE,PTR,SWAP##SIZE(VAL)) -# define GETSWAPPED(SIZE,PTR) SWAP##SIZE(GET(SIZE,PTR)) +# define PUT(SIZE,PTR,VAL) (((struct { uint##SIZE##_t i; } __attribute__((packed)) *)(PTR))->i = (VAL)) +# define GET(SIZE,PTR) (((const struct { uint##SIZE##_t i; } __attribute__((packed)) *)(PTR))->i) +# define PUTSWAPPED(SIZE,PTR,VAL) PUT(SIZE,PTR,SWAP##SIZE(VAL)) +# define GETSWAPPED(SIZE,PTR) SWAP##SIZE(GET(SIZE,PTR)) #endif /* To do: Define SWAP16, SWAP32, SWAP64 macros to byte-swap values with the indicated numbers of bits. @@ -520,25 +521,25 @@ typedef struct { int error; unsigned char did_run; } k5_init_t; #if defined(HAVE_BYTESWAP_H) && defined(HAVE_BSWAP_16) # include <byteswap.h> -# define SWAP16 bswap_16 -# define SWAP32 bswap_32 +# define SWAP16 bswap_16 +# define SWAP32 bswap_32 # ifdef HAVE_BSWAP_64 -# define SWAP64 bswap_64 +# define SWAP64 bswap_64 # endif #endif #if TARGET_OS_MAC # include <architecture/byte_order.h> # if 0 /* This causes compiler warnings. */ -# define SWAP16 OSSwapInt16 +# define SWAP16 OSSwapInt16 # else -# define SWAP16 k5_swap16 +# define SWAP16 k5_swap16 static inline unsigned int k5_swap16 (unsigned int x) { x &= 0xffff; return (x >> 8) | ((x & 0xff) << 8); } # endif -# define SWAP32 OSSwapInt32 -# define SWAP64 OSSwapInt64 +# define SWAP32 OSSwapInt32 +# define SWAP64 OSSwapInt64 #endif /* Note that on Windows at least this file can be included from C++ @@ -612,8 +613,8 @@ load_32_be (const void *cvp) return GETSWAPPED(32,p); #else return (p[3] | (p[2] << 8) - | ((uint32_t) p[1] << 16) - | ((uint32_t) p[0] << 24)); + | ((uint32_t) p[1] << 16) + | ((uint32_t) p[0] << 24)); #endif } static inline UINT64_TYPE @@ -769,51 +770,51 @@ k5_ntohll (UINT64_TYPE val) #ifdef HAVE_GETPWNAM_R # ifndef GETPWNAM_R_4_ARGS /* POSIX */ -# define k5_getpwnam_r(NAME, REC, BUF, BUFSIZE, OUT) \ - (getpwnam_r(NAME,REC,BUF,BUFSIZE,OUT) == 0 \ - ? (*(OUT) == NULL ? -1 : 0) : -1) +# define k5_getpwnam_r(NAME, REC, BUF, BUFSIZE, OUT) \ + (getpwnam_r(NAME,REC,BUF,BUFSIZE,OUT) == 0 \ + ? (*(OUT) == NULL ? -1 : 0) : -1) # else /* POSIX drafts? */ # ifdef GETPWNAM_R_RETURNS_INT -# define k5_getpwnam_r(NAME, REC, BUF, BUFSIZE, OUT) \ - (getpwnam_r(NAME,REC,BUF,BUFSIZE) == 0 \ - ? (*(OUT) = REC, 0) \ - : (*(OUT) = NULL, -1)) +# define k5_getpwnam_r(NAME, REC, BUF, BUFSIZE, OUT) \ + (getpwnam_r(NAME,REC,BUF,BUFSIZE) == 0 \ + ? (*(OUT) = REC, 0) \ + : (*(OUT) = NULL, -1)) # else # define k5_getpwnam_r(NAME, REC, BUF, BUFSIZE, OUT) \ - (*(OUT) = getpwnam_r(NAME,REC,BUF,BUFSIZE), *(OUT) == NULL ? -1 : 0) + (*(OUT) = getpwnam_r(NAME,REC,BUF,BUFSIZE), *(OUT) == NULL ? -1 : 0) # endif # endif #else /* no getpwnam_r, or can't figure out #args or return type */ /* Will get warnings about unused variables. */ # define k5_getpwnam_r(NAME, REC, BUF, BUFSIZE, OUT) \ - (*(OUT) = getpwnam(NAME), *(OUT) == NULL ? -1 : 0) + (*(OUT) = getpwnam(NAME), *(OUT) == NULL ? -1 : 0) #endif /* int k5_getpwuid_r(uid_t, blah blah) */ #ifdef HAVE_GETPWUID_R # ifndef GETPWUID_R_4_ARGS /* POSIX */ -# define k5_getpwuid_r(UID, REC, BUF, BUFSIZE, OUT) \ - (getpwuid_r(UID,REC,BUF,BUFSIZE,OUT) == 0 \ - ? (*(OUT) == NULL ? -1 : 0) : -1) +# define k5_getpwuid_r(UID, REC, BUF, BUFSIZE, OUT) \ + (getpwuid_r(UID,REC,BUF,BUFSIZE,OUT) == 0 \ + ? (*(OUT) == NULL ? -1 : 0) : -1) # else /* POSIX drafts? Yes, I mean to test GETPWNAM... here. Less junk to do at configure time. */ # ifdef GETPWNAM_R_RETURNS_INT -# define k5_getpwuid_r(UID, REC, BUF, BUFSIZE, OUT) \ - (getpwuid_r(UID,REC,BUF,BUFSIZE) == 0 \ - ? (*(OUT) = REC, 0) \ - : (*(OUT) = NULL, -1)) +# define k5_getpwuid_r(UID, REC, BUF, BUFSIZE, OUT) \ + (getpwuid_r(UID,REC,BUF,BUFSIZE) == 0 \ + ? (*(OUT) = REC, 0) \ + : (*(OUT) = NULL, -1)) # else # define k5_getpwuid_r(UID, REC, BUF, BUFSIZE, OUT) \ - (*(OUT) = getpwuid_r(UID,REC,BUF,BUFSIZE), *(OUT) == NULL ? -1 : 0) + (*(OUT) = getpwuid_r(UID,REC,BUF,BUFSIZE), *(OUT) == NULL ? -1 : 0) # endif # endif #else /* no getpwuid_r, or can't figure out #args or return type */ /* Will get warnings about unused variables. */ # define k5_getpwuid_r(UID, REC, BUF, BUFSIZE, OUT) \ - (*(OUT) = getpwuid(UID), *(OUT) == NULL ? -1 : 0) + (*(OUT) = getpwuid(UID), *(OUT) == NULL ? -1 : 0) #endif /* Ensure, if possible, that the indicated file descriptor won't be @@ -829,10 +830,10 @@ set_cloexec_fd(int fd) #if defined(F_SETFD) # ifdef FD_CLOEXEC if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) - return errno; + return errno; # else if (fcntl(fd, F_SETFD, 1) != 0) - return errno; + return errno; # endif #endif return 0; @@ -850,14 +851,14 @@ set_cloexec_file(FILE *f) with F_SETFD. */ #ifdef F_SETFD # ifdef FD_CLOEXEC -# define set_cloexec_fd(FD) (fcntl((FD), F_SETFD, FD_CLOEXEC) ? errno : 0) +# define set_cloexec_fd(FD) (fcntl((FD), F_SETFD, FD_CLOEXEC) ? errno : 0) # else -# define set_cloexec_fd(FD) (fcntl((FD), F_SETFD, 1) ? errno : 0) +# define set_cloexec_fd(FD) (fcntl((FD), F_SETFD, 1) ? errno : 0) # endif #else -# define set_cloexec_fd(FD) ((FD),0) +# define set_cloexec_fd(FD) ((FD),0) #endif -#define set_cloexec_file(F) set_cloexec_fd(fileno(F)) +#define set_cloexec_file(F) set_cloexec_fd(fileno(F)) #endif @@ -871,7 +872,7 @@ set_cloexec_file(FILE *f) #if defined(HAS_VA_COPY) || defined(va_copy) /* Do nothing. */ #elif defined(CAN_COPY_VA_LIST) -#define va_copy(dest, src) ((dest) = (src)) +#define va_copy(dest, src) ((dest) = (src)) #else /* Assume array type, but still simply copyable. @@ -879,7 +880,7 @@ set_cloexec_file(FILE *f) allocate some storage pointed to by the va_list, and in that case we'll just lose. If anyone cares, we could try to devise a test for that case. */ -#define va_copy(dest, src) memcmp(dest, src, sizeof(va_list)) +#define va_copy(dest, src) memcmp(dest, src, sizeof(va_list)) #endif /* Provide strlcpy/strlcat interfaces. */ @@ -903,7 +904,7 @@ vsnprintf(char *str, size_t size, const char *format, va_list args) length = _vscprintf(format, args_copy); va_end(args_copy); if (size) - _vsnprintf(str, size, format, args); + _vsnprintf(str, size, format, args); return length; } static inline int |
