From: Derrick Brashear Date: Sat, 20 Apr 2002 19:38:50 +0000 (+0000) Subject: make it all build on solaris. provide necessary files to set up a kaserver X-Git-Tag: openafs-stable-1_2_4~62 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=e6d790451d876142aba2efa1b52806e2f4018dde;p=packages%2Fo%2Fopenafs.git make it all build on solaris. provide necessary files to set up a kaserver and authenticate against it (albeit with "known" keys) --- diff --git a/acinclude.m4 b/acinclude.m4 index cdbbc7a0b..f83e0b10b 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -443,6 +443,7 @@ AC_CHECK_HEADERS(windows.h malloc.h winsock2.h direct.h io.h) AC_CHECK_HEADERS(security/pam_modules.h siad.h usersec.h) AC_CHECK_FUNCS(utimes random srandom getdtablesize snprintf re_comp re_exec) +AC_CHECK_FUNCS(setprogname getprogname) dnl Directory PATH handling if test "x$enable_transarc_paths" = "xyes" ; then diff --git a/src/tests/KeyFile b/src/tests/KeyFile new file mode 100644 index 000000000..a44163423 Binary files /dev/null and b/src/tests/KeyFile differ diff --git a/src/tests/Makefile.in b/src/tests/Makefile.in index 452adf138..f502622c2 100644 --- a/src/tests/Makefile.in +++ b/src/tests/Makefile.in @@ -168,11 +168,14 @@ TEST_SRCS = write-ro-file.c read-vs-mmap.c read-vs-mmap2.c \ blocks-new-file.c fsx.c afscp.c afscp_callback.c \ write-rand.c -EXTRA_OBJS = err.o errx.o warn.o warnx.o +EXTRA_OBJS = err.o errx.o warn.o warnx.o vwarn.o vwarnx.o verr.o verrx.o warnerr.o snprintf.o OpenAFS/OS.pm: OpenAFS/OS-$(MKAFS_OSTYPE).pm $(CP) OpenAFS/OS-$(MKAFS_OSTYPE).pm OpenAFS/OS.pm +fsx: fsx.o $(EXTRA_OBJS) + $(CC) $(LDFLAGS) -o $@ fsx.o $(EXTRA_OBJS) $(LIBS) + write-rand: write-rand.o $(EXTRA_OBJS) $(CC) $(LDFLAGS) -o $@ write-rand.o $(EXTRA_OBJS) $(LIBS) @@ -349,7 +352,7 @@ run-tests: run-tests.in # $(CC) -c $(CPPFLAGS) $(DEFS) -I$(srcdir) -I. $(REALCFLAGS) $< afscp: afscp.o afscp_callback.o $(EXTRA_OBJS) - $(CC) $(LDFLAGS) -o $@ afscp.o afscp_callback.o $(EXTRA_OBJS) $(INT_LIBS) + $(CC) $(LDFLAGS) -o $@ afscp.o afscp_callback.o $(EXTRA_OBJS) $(INT_LIBS) ${XLIBS} hello-world: hello-world.in sed -e "s!%CC%!$(CC)!" $(srcdir)/hello-world.in > $@ diff --git a/src/tests/OpenAFS/Auth-Kaserver.pm b/src/tests/OpenAFS/Auth-Kaserver.pm new file mode 100644 index 000000000..0055737a0 --- /dev/null +++ b/src/tests/OpenAFS/Auth-Kaserver.pm @@ -0,0 +1,44 @@ +# This is -*- perl -*- + +package OpenAFS::Auth; +use OpenAFS::Dirpath; + +use strict; +#use vars qw( @ISA @EXPORT ); +#@ISA = qw(Exporter); +#require Exporter; +#@EXPORT = qw($openafs-authadmin $openafs-authuser); + +sub getcell { + my($cell); + open(CELL, "$openafsdirpath->{'afsconfdir'}/ThisCell") + or die "Cannot open $openafsdirpath->{'afsconfdir'}/ThisCell: $!\n"; + $cell = ; + chomp $cell; + close CELL; + return $cell; +} + +sub getrealm { + my($cell); + open(CELL, "$openafsdirpath->{'afsconfdir'}/ThisCell") + or die "Cannot open $openafsdirpath->{'afsconfdir'}/ThisCell: $!\n"; + $cell = ; + chomp $cell; + close CELL; + $cell =~ tr/a-z/A-Z/; + return $cell; +} + +sub authadmin { + my $cell = &getrealm; + my $cmd = "echo \"Proceeding w/o authentication\"|klog -pipe admin\@${cell}"; + system($cmd); +} +sub authuser { + my $cell = &getrealm; + my $cmd = "echo \"Proceeding w/o authentication\"|klog -pipe user\@${cell}"; + system($cmd); +} + +1; diff --git a/src/tests/fs_lib.c b/src/tests/fs_lib.c index 04a56b374..f7c580bff 100644 --- a/src/tests/fs_lib.c +++ b/src/tests/fs_lib.c @@ -129,7 +129,7 @@ fs_getfilecellname(char *path, char *cell, size_t len) #ifdef VIOC_SETRXKCRYPT int -fs_setcrypt (u_int32_t n) +fs_setcrypt (afs_uint32 n) { struct ViceIoctl a_params; @@ -151,7 +151,7 @@ fs_setcrypt (u_int32_t n) #ifdef VIOC_GETRXKCRYPT int -fs_getcrypt (u_int32_t *level) +fs_getcrypt (afs_uint32 *level) { struct ViceIoctl a_params; @@ -173,12 +173,12 @@ fs_getcrypt (u_int32_t *level) #ifdef VIOCCONNECTMODE int -fs_connect(int32_t type, int32_t *flags) +fs_connect(afs_int32 type, afs_int32 *flags) { struct ViceIoctl a_params; a_params.in_size = sizeof(type); - a_params.out_size = sizeof (int32_t); + a_params.out_size = sizeof (afs_int32); a_params.in = (char *) &type; a_params.out = (char *) flags; @@ -293,12 +293,12 @@ fs_getmaxfprio(int16_t *maxprio) #ifdef VIOCGETCACHEPARAMS int -fs_getfilecachestats(u_int32_t *max_bytes, - u_int32_t *used_bytes, - u_int32_t *max_vnodes, - u_int32_t *used_vnodes) +fs_getfilecachestats(afs_uint32 *max_bytes, + afs_uint32 *used_bytes, + afs_uint32 *max_vnodes, + afs_uint32 *used_vnodes) { - u_int32_t parms[16]; + afs_uint32 parms[16]; struct ViceIoctl a_params; a_params.in_size = 0; @@ -332,10 +332,10 @@ fs_getfilecachestats(u_int32_t *max_bytes, #ifdef VIOC_AVIATOR int -fs_getaviatorstats(u_int32_t *max_workers, - u_int32_t *used_workers) +fs_getaviatorstats(afs_uint32 *max_workers, + afs_uint32 *used_workers) { - u_int32_t parms[16]; + afs_uint32 parms[16]; struct ViceIoctl a_params; a_params.in_size = 0; @@ -384,10 +384,10 @@ fs_gcpags(void) #ifdef VIOC_CALCULATE_CACHE int -fs_calculate_cache(u_int32_t *calculated, - u_int32_t *usedbytes) +fs_calculate_cache(afs_uint32 *calculated, + afs_uint32 *usedbytes) { - u_int32_t parms[16]; + afs_uint32 parms[16]; struct ViceIoctl a_params; a_params.in_size = 0; @@ -441,8 +441,8 @@ debug (int pioctl_cmd, int inflags, int *outflags, char *pathname) { struct ViceIoctl a_params; - int32_t rinflags = inflags; - int32_t routflags; + afs_int32 rinflags = inflags; + afs_int32 routflags; if (inflags != -1) { a_params.in_size = sizeof(rinflags); @@ -513,7 +513,7 @@ arla_debug (int inflags, int *outflags) */ int -fs_checkservers(char *cell, int32_t flags, u_int32_t *hosts, int numhosts) +fs_checkservers(char *cell, afs_int32 flags, afs_uint32 *hosts, int numhosts) { struct ViceIoctl a_params; char *in = NULL; @@ -521,15 +521,15 @@ fs_checkservers(char *cell, int32_t flags, u_int32_t *hosts, int numhosts) size_t insize; if (cell != NULL) { - insize = strlen(cell) + sizeof(int32_t) + 1; + insize = strlen(cell) + sizeof(afs_int32) + 1; in = malloc (insize); if (in == NULL) errx (1, "malloc"); memcpy (in, &flags, sizeof(flags)); - memcpy (in + sizeof(int32_t), cell, strlen(cell)); - in[sizeof(int32_t) + strlen(cell)] = '\0'; + memcpy (in + sizeof(afs_int32), cell, strlen(cell)); + in[sizeof(afs_int32) + strlen(cell)] = '\0'; a_params.in_size = insize; a_params.in = in; @@ -538,7 +538,7 @@ fs_checkservers(char *cell, int32_t flags, u_int32_t *hosts, int numhosts) a_params.in = (caddr_t )&flags; } - a_params.out_size = numhosts * sizeof(u_int32_t); + a_params.out_size = numhosts * sizeof(afs_uint32); a_params.out = (caddr_t)hosts; ret = 0; @@ -580,7 +580,7 @@ int fs_set_sysname (const char *sys) { struct ViceIoctl a_params; - int32_t set = 1; + afs_int32 set = 1; a_params.in_size = sizeof(set) + strlen(sys) + 1; a_params.in = malloc(a_params.in_size); @@ -605,14 +605,14 @@ int fs_setcache(int lv, int hv, int lb, int hb) { struct ViceIoctl a_params; - u_int32_t s[4]; + afs_uint32 s[4]; s[0] = lv; s[1] = hv; s[2] = lb; s[3] = hb; - a_params.in_size = ((hv == 0) ? 1 : 4) * sizeof(u_int32_t); + a_params.in_size = ((hv == 0) ? 1 : 4) * sizeof(afs_uint32); a_params.out_size = 0; a_params.in = (void *)s; a_params.out = NULL; @@ -690,9 +690,9 @@ int fs_venuslog (void) { struct ViceIoctl a_params; - int32_t status = 0; /* XXX not really right, but anyway */ + afs_int32 status = 0; /* XXX not really right, but anyway */ - a_params.in_size = sizeof(int32_t); + a_params.in_size = sizeof(afs_int32); a_params.out_size = 0; a_params.in = (caddr_t) &status; a_params.out = NULL; @@ -708,12 +708,12 @@ fs_venuslog (void) */ int -fs_getcellstatus (char *cellname, u_int32_t *flags) +fs_getcellstatus (char *cellname, afs_uint32 *flags) { struct ViceIoctl a_params; a_params.in_size = strlen (cellname) + 1; - a_params.out_size = sizeof (u_int32_t); + a_params.out_size = sizeof (afs_uint32); a_params.in = cellname; a_params.out = (caddr_t) flags; diff --git a/src/tests/fsx.c b/src/tests/fsx.c index 0b67ae8bc..7ec207589 100644 --- a/src/tests/fsx.c +++ b/src/tests/fsx.c @@ -11,7 +11,7 @@ #include #include -#if defined(_UWIN) || defined(__linux) +#if defined(sun) || defined(_UWIN) || defined(__linux) # include # include # include @@ -31,6 +31,17 @@ #include #include #include +#include + +#if !defined L_SET +# define L_SET SEEK_SET +#endif +#if !defined L_INCR +# define L_INCR SEEK_CUR +#endif +#if !defined L_XTND +# define L_XTND SEEK_END +#endif #define NUMPRINTCOLUMNS 32 /* # columns of data to print on each line */ diff --git a/src/tests/kaserver.DB0 b/src/tests/kaserver.DB0 new file mode 100644 index 000000000..d8edd3734 Binary files /dev/null and b/src/tests/kaserver.DB0 differ diff --git a/src/tests/kaserver.DBSYS1 b/src/tests/kaserver.DBSYS1 new file mode 100644 index 000000000..9017fd98b Binary files /dev/null and b/src/tests/kaserver.DBSYS1 differ diff --git a/src/tests/make-page.c b/src/tests/make-page.c index 9a042997d..907aa4d09 100644 --- a/src/tests/make-page.c +++ b/src/tests/make-page.c @@ -45,7 +45,7 @@ #include #include #include - +#include #include diff --git a/src/tests/run-suite.pl b/src/tests/run-suite.pl index d1559d630..f0fffe5b0 100755 --- a/src/tests/run-suite.pl +++ b/src/tests/run-suite.pl @@ -148,11 +148,19 @@ run("echo /afs:/usr/vice/cache:${cachesize} >$openafsdirpath->{'viceetcdir'}/cac run("$openafsinitcmd->{'client-forcestart'}"); my $afs_running = 0; open(MOUNT, "mount |") or die "Failed to run mount: $!\n"; + if(m:^AFS:) { + print "The AFS client is currently running on this workstation.\n"; + print "Please restart this script after running $openafsinitcmd->{'client-stop'}\n"; + exit(1); + } while() { -if(m:^AFS:) { - $afs_running = 1; + if(m:^AFS:) { + $afs_running = 1; + } + if(m:^/afs on AFS:) { + $afs_running = 1; + } } - } unless ($afs_running) { print "*** The AFS client failed to start.\n"; print "Please fix whatever problem kept it from running.\n"; diff --git a/src/tests/snprintf.c b/src/tests/snprintf.c new file mode 100644 index 000000000..995d61ce7 --- /dev/null +++ b/src/tests/snprintf.c @@ -0,0 +1,628 @@ +/* + * Copyright (c) 1995-2000 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifdef HAVE_CONFIG_H +#include +RCSID("$Id$"); +#endif +#include +#include +#include +#include +#include + +#ifndef min +#define min(a, b) ((a) > (b) ? (b) : (a)) +#endif +#ifndef max +#define max(a, b) ((a) < (b) ? (b) : (a)) +#endif + +enum format_flags { + minus_flag = 1, + plus_flag = 2, + space_flag = 4, + alternate_flag = 8, + zero_flag = 16 +}; + +/* + * Common state + */ + +struct state { + unsigned char *str; + unsigned char *s; + unsigned char *theend; + size_t sz; + size_t max_sz; + int (*append_char)(struct state *, unsigned char); + int (*reserve)(struct state *, size_t); + /* XXX - methods */ +}; + +#ifndef HAVE_VSNPRINTF +static int +sn_reserve (struct state *state, size_t n) +{ + return state->s + n > state->theend; +} + +static int +sn_append_char (struct state *state, unsigned char c) +{ + if (sn_reserve (state, 1)) { + return 1; + } else { + *state->s++ = c; + return 0; + } +} +#endif + +static int +as_reserve (struct state *state, size_t n) +{ + if (state->s + n > state->theend) { + int off = state->s - state->str; + unsigned char *tmp; + + if (state->max_sz && state->sz >= state->max_sz) + return 1; + + state->sz = max(state->sz * 2, state->sz + n); + if (state->max_sz) + state->sz = min(state->sz, state->max_sz); + tmp = realloc (state->str, state->sz); + if (tmp == NULL) + return 1; + state->str = tmp; + state->s = state->str + off; + state->theend = state->str + state->sz - 1; + } + return 0; +} + +static int +as_append_char (struct state *state, unsigned char c) +{ + if(as_reserve (state, 1)) + return 1; + else { + *state->s++ = c; + return 0; + } +} + +static int +append_number(struct state *state, + unsigned long num, unsigned base, char *rep, + int width, int prec, int flags, int minusp) +{ + int len = 0; + int i; + + /* given precision, ignore zero flag */ + if(prec != -1) + flags &= ~zero_flag; + else + prec = 1; + /* zero value with zero precision -> "" */ + if(prec == 0 && num == 0) + return 0; + do{ + if((*state->append_char)(state, rep[num % base])) + return 1; + len++; + num /= base; + }while(num); + prec -= len; + /* pad with prec zeros */ + while(prec-- > 0){ + if((*state->append_char)(state, '0')) + return 1; + len++; + } + /* add length of alternate prefix (added later) to len */ + if(flags & alternate_flag && (base == 16 || base == 8)) + len += base / 8; + /* pad with zeros */ + if(flags & zero_flag){ + width -= len; + if(minusp || (flags & space_flag) || (flags & plus_flag)) + width--; + while(width-- > 0){ + if((*state->append_char)(state, '0')) + return 1; + len++; + } + } + /* add alternate prefix */ + if(flags & alternate_flag && (base == 16 || base == 8)){ + if(base == 16) + if((*state->append_char)(state, rep[10] + 23)) /* XXX */ + return 1; + if((*state->append_char)(state, '0')) + return 1; + } + /* add sign */ + if(minusp){ + if((*state->append_char)(state, '-')) + return 1; + len++; + } else if(flags & plus_flag) { + if((*state->append_char)(state, '+')) + return 1; + len++; + } else if(flags & space_flag) { + if((*state->append_char)(state, ' ')) + return 1; + len++; + } + if(flags & minus_flag) + /* swap before padding with spaces */ + for(i = 0; i < len / 2; i++){ + char c = state->s[-i-1]; + state->s[-i-1] = state->s[-len+i]; + state->s[-len+i] = c; + } + width -= len; + while(width-- > 0){ + if((*state->append_char)(state, ' ')) + return 1; + len++; + } + if(!(flags & minus_flag)) + /* swap after padding with spaces */ + for(i = 0; i < len / 2; i++){ + char c = state->s[-i-1]; + state->s[-i-1] = state->s[-len+i]; + state->s[-len+i] = c; + } + + return 0; +} + +static int +append_string (struct state *state, + unsigned char *arg, + int width, + int prec, + int flags) +{ + if(arg == NULL) + arg = (unsigned char*)"(null)"; + + if(prec != -1) + width -= prec; + else + width -= strlen((char *)arg); + if(!(flags & minus_flag)) + while(width-- > 0) + if((*state->append_char) (state, ' ')) + return 1; + if (prec != -1) { + while (*arg && prec--) + if ((*state->append_char) (state, *arg++)) + return 1; + } else { + while (*arg) + if ((*state->append_char) (state, *arg++)) + return 1; + } + if(flags & minus_flag) + while(width-- > 0) + if((*state->append_char) (state, ' ')) + return 1; + return 0; +} + +static int +append_char(struct state *state, + unsigned char arg, + int width, + int flags) +{ + while(!(flags & minus_flag) && --width > 0) + if((*state->append_char) (state, ' ')) + return 1; + + if((*state->append_char) (state, arg)) + return 1; + while((flags & minus_flag) && --width > 0) + if((*state->append_char) (state, ' ')) + return 1; + + return 0; +} + +/* + * This can't be made into a function... + */ + +#define PARSE_INT_FORMAT(res, arg, unsig) \ +if (long_flag) \ + res = (unsig long)va_arg(arg, unsig long); \ +else if (short_flag) \ + res = (unsig short)va_arg(arg, unsig int); \ +else \ + res = (unsig int)va_arg(arg, unsig int) + +/* + * zyxprintf - return 0 or -1 + */ + +static int +xyzprintf (struct state *state, const char *char_format, va_list ap) +{ + const unsigned char *format = (const unsigned char *)char_format; + unsigned char c; + + while((c = *format++)) { + if (c == '%') { + int flags = 0; + int width = 0; + int prec = -1; + int long_flag = 0; + int short_flag = 0; + + /* flags */ + while((c = *format++)){ + if(c == '-') + flags |= minus_flag; + else if(c == '+') + flags |= plus_flag; + else if(c == ' ') + flags |= space_flag; + else if(c == '#') + flags |= alternate_flag; + else if(c == '0') + flags |= zero_flag; + else + break; + } + + if((flags & space_flag) && (flags & plus_flag)) + flags ^= space_flag; + + if((flags & minus_flag) && (flags & zero_flag)) + flags ^= zero_flag; + + /* width */ + if (isdigit(c)) + do { + width = width * 10 + c - '0'; + c = *format++; + } while(isdigit(c)); + else if(c == '*') { + width = va_arg(ap, int); + c = *format++; + } + + /* precision */ + if (c == '.') { + prec = 0; + c = *format++; + if (isdigit(c)) + do { + prec = prec * 10 + c - '0'; + c = *format++; + } while(isdigit(c)); + else if (c == '*') { + prec = va_arg(ap, int); + c = *format++; + } + } + + /* size */ + + if (c == 'h') { + short_flag = 1; + c = *format++; + } else if (c == 'l') { + long_flag = 1; + c = *format++; + } + + switch (c) { + case 'c' : + if(append_char(state, va_arg(ap, int), width, flags)) + return -1; + break; + case 's' : + if (append_string(state, + va_arg(ap, unsigned char*), + width, + prec, + flags)) + return -1; + break; + case 'd' : + case 'i' : { + long arg; + unsigned long num; + int minusp = 0; + + PARSE_INT_FORMAT(arg, ap, signed); + + if (arg < 0) { + minusp = 1; + num = -arg; + } else + num = arg; + + if (append_number (state, num, 10, "0123456789", + width, prec, flags, minusp)) + return -1; + break; + } + case 'u' : { + unsigned long arg; + + PARSE_INT_FORMAT(arg, ap, unsigned); + + if (append_number (state, arg, 10, "0123456789", + width, prec, flags, 0)) + return -1; + break; + } + case 'o' : { + unsigned long arg; + + PARSE_INT_FORMAT(arg, ap, unsigned); + + if (append_number (state, arg, 010, "01234567", + width, prec, flags, 0)) + return -1; + break; + } + case 'x' : { + unsigned long arg; + + PARSE_INT_FORMAT(arg, ap, unsigned); + + if (append_number (state, arg, 0x10, "0123456789abcdef", + width, prec, flags, 0)) + return -1; + break; + } + case 'X' :{ + unsigned long arg; + + PARSE_INT_FORMAT(arg, ap, unsigned); + + if (append_number (state, arg, 0x10, "0123456789ABCDEF", + width, prec, flags, 0)) + return -1; + break; + } + case 'p' : { + unsigned long arg = (unsigned long)va_arg(ap, void*); + + if (append_number (state, arg, 0x10, "0123456789ABCDEF", + width, prec, flags, 0)) + return -1; + break; + } + case 'n' : { + int *arg = va_arg(ap, int*); + *arg = state->s - state->str; + break; + } + case '\0' : + --format; + /* FALLTHROUGH */ + case '%' : + if ((*state->append_char)(state, c)) + return -1; + break; + default : + if ( (*state->append_char)(state, '%') + || (*state->append_char)(state, c)) + return -1; + break; + } + } else + if ((*state->append_char) (state, c)) + return -1; + } + return 0; +} + +#ifndef HAVE_SNPRINTF +int +snprintf (char *str, size_t sz, const char *format, ...) +{ + va_list args; + int ret; + + va_start(args, format); + ret = vsnprintf (str, sz, format, args); + +#ifdef PARANOIA + { + int ret2; + char *tmp; + + tmp = malloc (sz); + if (tmp == NULL) + abort (); + + ret2 = vsprintf (tmp, format, args); + if (ret != ret2 || strcmp(str, tmp)) + abort (); + free (tmp); + } +#endif + + va_end(args); + return ret; +} +#endif + +#ifndef HAVE_ASPRINTF +int +asprintf (char **ret, const char *format, ...) +{ + va_list args; + int val; + + va_start(args, format); + val = vasprintf (ret, format, args); + +#ifdef PARANOIA + { + int ret2; + char *tmp; + tmp = malloc (val + 1); + if (tmp == NULL) + abort (); + + ret2 = vsprintf (tmp, format, args); + if (val != ret2 || strcmp(*ret, tmp)) + abort (); + free (tmp); + } +#endif + + va_end(args); + return val; +} +#endif + +#ifndef HAVE_ASNPRINTF +int +asnprintf (char **ret, size_t max_sz, const char *format, ...) +{ + va_list args; + int val; + + va_start(args, format); + val = vasnprintf (ret, max_sz, format, args); + +#ifdef PARANOIA + { + int ret2; + char *tmp; + tmp = malloc (val + 1); + if (tmp == NULL) + abort (); + + ret2 = vsprintf (tmp, format, args); + if (val != ret2 || strcmp(*ret, tmp)) + abort (); + free (tmp); + } +#endif + + va_end(args); + return val; +} +#endif + +#ifndef HAVE_VASPRINTF +int +vasprintf (char **ret, const char *format, va_list args) +{ + return vasnprintf (ret, 0, format, args); +} +#endif + + +#ifndef HAVE_VASNPRINTF +int +vasnprintf (char **ret, size_t max_sz, const char *format, va_list args) +{ + int st; + size_t len; + struct state state; + + state.max_sz = max_sz; + state.sz = 1; + state.str = malloc(state.sz); + if (state.str == NULL) { + *ret = NULL; + return -1; + } + state.s = state.str; + state.theend = state.s + state.sz - 1; + state.append_char = as_append_char; + state.reserve = as_reserve; + + st = xyzprintf (&state, format, args); + if (st) { + free (state.str); + *ret = NULL; + return -1; + } else { + char *tmp; + + *state.s = '\0'; + len = state.s - state.str; + tmp = realloc (state.str, len+1); + if (tmp == NULL) { + free (state.str); + *ret = NULL; + return -1; + } + *ret = tmp; + return len; + } +} +#endif + +#ifndef HAVE_VSNPRINTF +int +vsnprintf (char *str, size_t sz, const char *format, va_list args) +{ + struct state state; + int ret; + unsigned char *ustr = (unsigned char *)str; + + state.max_sz = 0; + state.sz = sz; + state.str = ustr; + state.s = ustr; + state.theend = ustr + sz - 1; + state.append_char = sn_append_char; + state.reserve = sn_reserve; + + ret = xyzprintf (&state, format, args); + *state.s = '\0'; + if (ret) + return sz; + else + return state.s - state.str; +} +#endif + diff --git a/src/tests/verr.c b/src/tests/verr.c new file mode 100644 index 000000000..aab4e44ed --- /dev/null +++ b/src/tests/verr.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 1995 - 2001 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifdef HAVE_CONFIG_H +#include +RCSID("$Id$"); +#endif + +#include + +void +verr(int eval, const char *fmt, va_list ap) +{ + warnerr(1, fmt, ap); + exit(eval); +} diff --git a/src/tests/verrx.c b/src/tests/verrx.c new file mode 100644 index 000000000..c45cd7ce4 --- /dev/null +++ b/src/tests/verrx.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 1995 - 2001 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifdef HAVE_CONFIG_H +#include +RCSID("$Id$"); +#endif + +#include + +void +verrx(int eval, const char *fmt, va_list ap) +{ + warnerr(0, fmt, ap); + exit(eval); +} diff --git a/src/tests/vwarn.c b/src/tests/vwarn.c new file mode 100644 index 000000000..3f0561f91 --- /dev/null +++ b/src/tests/vwarn.c @@ -0,0 +1,45 @@ +/* + * Copyright (c) 1995 - 2001 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifdef HAVE_CONFIG_H +#include +RCSID("$Id$"); +#endif + +#include + +void +vwarn(const char *fmt, va_list ap) +{ + warnerr(1, fmt, ap); +} diff --git a/src/tests/vwarnx.c b/src/tests/vwarnx.c new file mode 100644 index 000000000..b3a507bcc --- /dev/null +++ b/src/tests/vwarnx.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 1995 - 2001 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifdef HAVE_CONFIG_H +#include +RCSID("$Id$"); +#endif + +#include + +void +vwarnx(const char *fmt, va_list ap) +{ + warnerr(0, fmt, ap); +} + diff --git a/src/tests/warnerr.c b/src/tests/warnerr.c new file mode 100644 index 000000000..d61a80178 --- /dev/null +++ b/src/tests/warnerr.c @@ -0,0 +1,102 @@ +/* + * Copyright (c) 1995 - 2001 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifdef HAVE_CONFIG_H +#include +RCSID("$Id$"); +#endif + +#include "err.h" + +#ifndef HAVE___PROGNAME +const char *__progname; +#endif + +#ifndef HAVE_GETPROGNAME +const char * +getprogname(void) +{ + return __progname; +} +#endif + +#ifndef HAVE_SETPROGNAME +void +setprogname(const char *argv0) +{ +#ifndef HAVE___PROGNAME + char *p; + if(argv0 == NULL) + return; + p = strrchr(argv0, '/'); + if(p == NULL) + p = argv0; + else + p++; + __progname = p; +#endif +} +#endif /* HAVE_SETPROGNAME */ + +void +set_progname(char *argv0) +{ + setprogname ((const char *)argv0); +} + +const char * +get_progname (void) +{ + return getprogname (); +} + +void +warnerr(int doerrno, const char *fmt, va_list ap) +{ + int sverrno = errno; + const char *progname = getprogname(); + + if(progname != NULL){ + fprintf(stderr, "%s", progname); + if(fmt != NULL || doerrno) + fprintf(stderr, ": "); + } + if (fmt != NULL){ + vfprintf(stderr, fmt, ap); + if(doerrno) + fprintf(stderr, ": "); + } + if(doerrno) + fprintf(stderr, "%s", strerror(sverrno)); + fprintf(stderr, "\n"); +} diff --git a/src/tests/write-rand.c b/src/tests/write-rand.c index 655eb1188..764ee78ae 100644 --- a/src/tests/write-rand.c +++ b/src/tests/write-rand.c @@ -84,7 +84,7 @@ int main (int argc, char **argv) { const char *file; - const size_t sz; + size_t sz; char *random_buf; char *read_buf1; char *read_buf2;