From d4cd7a3d4bea0bd549b405d89563252d8de95363 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Sun, 9 Sep 2001 16:09:19 +0000 Subject: [PATCH] more bug fixesand some warning cleanups --- ChangeLog | 10 +++++++++ THANKS | 1 + TODO | 4 ++++ cipher/ChangeLog | 4 ++++ cipher/random.c | 2 +- cipher/rsa.c | 12 ++++++----- configure.ac | 8 +++---- g10/ChangeLog | 20 ++++++++++++++++++ g10/getkey.c | 3 ++- g10/keyedit.c | 2 +- g10/keygen.c | 46 ++++++++++++++++++++-------------------- g10/keylist.c | 6 +++--- g10/keyring.c | 2 +- g10/keyring.o | Bin 56784 -> 56848 bytes g10/misc.c | 17 +++++++-------- g10/parse-packet.c | 4 +++- g10/passphrase.c | 2 +- g10/pubkey-enc.c | 4 ++-- g10/sign.c | 16 +++++++------- include/ChangeLog | 4 ++++ include/util.h | 3 +++ util/ChangeLog | 4 ++++ util/strgutil.c | 51 ++++++++++++++++++++++++++++++++++++++++++++- 23 files changed, 164 insertions(+), 61 deletions(-) diff --git a/ChangeLog b/ChangeLog index e2ae693fd..1441f180d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2001-09-09 Werner Koch + + * configure.ac: autoconf changed the name of the maintainer mode + flag, so that not all warnings where enabled. Fixed that. + Reported by Dirk Meyer. + +2001-09-07 Werner Koch + + * configure.ac: Test for strsep(). + 2001-09-03 Werner Koch * configure.ac: Removed GDBM tests. diff --git a/THANKS b/THANKS index 2af6975d4..ee7a0ad4c 100644 --- a/THANKS +++ b/THANKS @@ -41,6 +41,7 @@ David R. Bergstein dbergstein@home.com Detlef Lannert lannert@lannert.rz.uni-duesseldorf.de Dimitri dmitri@advantrix.com Dirk Lattermann dlatt@t-online.de +Dirk Meyer dirk.meyer@dinoex.sub.org Ed Boraas ecxjo@esperanto.org Edmund GRIMLEY EVANS edmundo@rano.org Edwin Woudt edwin@woudt.nl diff --git a/TODO b/TODO index 078262c63..66a1c43c3 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,8 @@ + * 12345678! does not work anymore + + * Always use the primary key to sign other keys. + * add listing of notation data * Check the changes to the gpg random gatherer on all W32 platforms. diff --git a/cipher/ChangeLog b/cipher/ChangeLog index dd20e1e2d..9174d424b 100644 --- a/cipher/ChangeLog +++ b/cipher/ChangeLog @@ -1,3 +1,7 @@ +2001-09-09 Werner Koch + + * rsa.c (rsa_get_info): s/usage/r_usage/ to avoid shadow warnings. + 2001-08-24 Werner Koch * md.c (md_write): Made buf arg const. diff --git a/cipher/random.c b/cipher/random.c index cdbd0b700..30c94b5b9 100644 --- a/cipher/random.c +++ b/cipher/random.c @@ -296,7 +296,7 @@ set_random_seed_file( const char *name ) * and return true if this was successful */ static int -read_seed_file() +read_seed_file(void) { int fd; struct stat sb; diff --git a/cipher/rsa.c b/cipher/rsa.c index 9e6343f4f..c7078ea1d 100644 --- a/cipher/rsa.c +++ b/cipher/rsa.c @@ -446,7 +446,7 @@ rsa_get_nbits( int algo, MPI *pkey ) */ const char * rsa_get_info( int algo, - int *npkey, int *nskey, int *nenc, int *nsig, int *usage ) + int *npkey, int *nskey, int *nenc, int *nsig, int *r_usage ) { *npkey = 2; *nskey = 6; @@ -454,10 +454,12 @@ rsa_get_info( int algo, *nsig = 1; switch( algo ) { - case 1: *usage = PUBKEY_USAGE_SIG | PUBKEY_USAGE_ENC; return "RSA"; - case 2: *usage = PUBKEY_USAGE_ENC; return "RSA-E"; - case 3: *usage = PUBKEY_USAGE_SIG; return "RSA-S"; - default:*usage = 0; return NULL; + case 1: *r_usage = PUBKEY_USAGE_SIG | PUBKEY_USAGE_ENC; return "RSA"; + case 2: *r_usage = PUBKEY_USAGE_ENC; return "RSA-E"; + case 3: *r_usage = PUBKEY_USAGE_SIG; return "RSA-S"; + default:*r_usage = 0; return NULL; } } + + diff --git a/configure.ac b/configure.ac index 608bdbdbe..814fe22e8 100644 --- a/configure.ac +++ b/configure.ac @@ -21,7 +21,7 @@ dnl (Process this file with autoconf to produce a configure script.) AC_REVISION($Revision$)dnl AC_PREREQ(2.52) -AC_INIT(gnupg,1.0.6a) +AC_INIT(gnupg,1.0.6b) AC_CONFIG_SRCDIR(g10/g10.c) AC_CONFIG_AUX_DIR(scripts) AC_CONFIG_HEADERS(config.h) @@ -449,10 +449,10 @@ fi dnl Checks for library functions. AC_FUNC_FSEEKO AC_FUNC_VPRINTF -AC_CHECK_FUNCS(strerror stpcpy strlwr stricmp tcgetattr rand strtoul mmap) +AC_CHECK_FUNCS(strerror stpcpy strsep strlwr stricmp tcgetattr strtoul mmap) AC_CHECK_FUNCS(memmove gettimeofday getrusage setrlimit clock_gettime) AC_CHECK_FUNCS(memicmp atexit raise getpagesize strftime nl_langinfo) -AC_CHECK_FUNCS(waitpid wait4 sigaction sigprocmask) +AC_CHECK_FUNCS(waitpid wait4 sigaction sigprocmask rand) # # check for gethrtime and run a testprogram to see whether @@ -794,7 +794,7 @@ esac if test "$GCC" = yes; then - if test "$MAINTAINER_MODE" = "yes"; then + if test "$USE_MAINTAINER_MODE" = "yes"; then CFLAGS="$CFLAGS -Wall -Wcast-align -Wshadow -Wstrict-prototypes" else CFLAGS="$CFLAGS -Wall" diff --git a/g10/ChangeLog b/g10/ChangeLog index 0345c7f00..e12c6b2a8 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,23 @@ +2001-09-09 Werner Koch + + * keyedit.c (keyedit_menu): No need to define another p. + + * keylist.c (print_capabilities): s/used/use/ so that it + does not shadow a global. + * sign.c (sign_file): Renamed arg encrypt to encryptflag + * keygen.c: Replaced all "usage" by "use". + * misc.c (openpgp_pk_algo_usage): Ditto. + + * pubkey-enc.c (get_it): Renamed arg k to enc so that the later + defined k does not shadow it. + + * parse-packet.c (parse_gpg_control): No need to define another i. + + * getkey.c (get_pubkey_byfprint): Must use the enum values and not + the fprint_len. + * keyring.c (keyring_search): Removed a non-sense break. Both + bugs pointed out by Stefan. + 2001-09-07 Werner Koch * status.c, status.h: Added NO_RECP and ALREADY_SIGNED. diff --git a/g10/getkey.c b/g10/getkey.c index 31ace1703..d514ad0f7 100644 --- a/g10/getkey.c +++ b/g10/getkey.c @@ -911,7 +911,8 @@ get_pubkey_byfprint( PKT_public_key *pk, ctx.not_allocated = 1; ctx.kr_handle = keydb_new (0); ctx.nitems = 1; - ctx.items[0].mode = fprint_len; + ctx.items[0].mode = fprint_len==16? KEYDB_SEARCH_MODE_FPR16 + : KEYDB_SEARCH_MODE_FPR20; memcpy( ctx.items[0].u.fpr, fprint, fprint_len ); rc = lookup( &ctx, &kb, 0 ); if (!rc && pk ) diff --git a/g10/keyedit.c b/g10/keyedit.c index d1cc9da38..87a971bf7 100644 --- a/g10/keyedit.c +++ b/g10/keyedit.c @@ -955,7 +955,7 @@ keyedit_menu( const char *username, STRLIST locusr, STRLIST commands, case cmdUPDPREF: { - char *p = keygen_get_std_prefs (); + p = keygen_get_std_prefs (); tty_printf (("Current preference list: %s\n"), p); m_free (p); } diff --git a/g10/keygen.c b/g10/keygen.c index e7614bc52..a6a2104f4 100644 --- a/g10/keygen.c +++ b/g10/keygen.c @@ -124,17 +124,17 @@ write_uid( KBNODE root, const char *s ) } static void -do_add_key_flags (PKT_signature *sig, unsigned int usage) +do_add_key_flags (PKT_signature *sig, unsigned int use) { byte buf[1]; - if (!usage) + if (!use) return; buf[0] = 0; - if (usage & PUBKEY_USAGE_SIG) + if (use & PUBKEY_USAGE_SIG) buf[0] |= 0x01 | 0x02; - if (usage & PUBKEY_USAGE_ENC) + if (use & PUBKEY_USAGE_ENC) buf[0] |= 0x04 | 0x08; build_sig_subpkt (sig, SIGSUBPKT_KEY_FLAGS, buf, 1); } @@ -292,7 +292,7 @@ add_feature_mdc (PKT_signature *sig) return; /* already set */ if (!s || !n) { /* create a new one */ n = 1; - buf = m_alloc (n); + buf = m_alloc_clear (n); } else { buf = m_alloc (n); @@ -358,7 +358,7 @@ keygen_add_std_prefs( PKT_signature *sig, void *opaque ) static int write_selfsig( KBNODE root, KBNODE pub_root, PKT_secret_key *sk, - unsigned int usage ) + unsigned int use ) { PACKET *pkt; PKT_signature *sig; @@ -380,7 +380,7 @@ write_selfsig( KBNODE root, KBNODE pub_root, PKT_secret_key *sk, if( !node ) BUG(); pk = node->pkt->pkt.public_key; - pk->pubkey_usage = usage; + pk->pubkey_usage = use; /* we have to cache the key, so that the verification of the signature * creation is able to retrieve the public key */ cache_public_key (pk); @@ -402,7 +402,7 @@ write_selfsig( KBNODE root, KBNODE pub_root, PKT_secret_key *sk, static int write_keybinding( KBNODE root, KBNODE pub_root, PKT_secret_key *sk, - unsigned int usage ) + unsigned int use ) { PACKET *pkt; PKT_signature *sig; @@ -433,7 +433,7 @@ write_keybinding( KBNODE root, KBNODE pub_root, PKT_secret_key *sk, BUG(); /* and make the signature */ - oduap.usage = usage; + oduap.usage = use; oduap.pk = subpk; rc = make_keysig_packet( &sig, pk, NULL, subpk, sk, 0x18, 0, 0, keygen_add_key_flags_and_expire, &oduap ); @@ -1296,26 +1296,26 @@ parse_parameter_usage (const char *fname, { struct para_data_s *r = get_parameter( para, key ); char *p, *pn; - unsigned int usage; + unsigned int use; if( !r ) return 0; /* none (this is an optional parameter)*/ - usage = 0; + use = 0; pn = r->u.value; while ( (p = strsep (&pn, " \t,")) ) { if ( !*p) ; else if ( !ascii_strcasecmp (p, "sign") ) - usage |= PUBKEY_USAGE_SIG; + use |= PUBKEY_USAGE_SIG; else if ( !ascii_strcasecmp (p, "encrypt") ) - usage |= PUBKEY_USAGE_ENC; + use |= PUBKEY_USAGE_ENC; else { log_error("%s:%d: invalid usage list\n", fname, r->lnr ); return -1; /* error */ } } - r->u.usage = usage; + r->u.usage = use; return 0; } @@ -1662,7 +1662,7 @@ generate_keypair( const char *fname ) DEK *dek; STRING2KEY *s2k; int algo; - unsigned int usage; + unsigned int use; int both = 0; u32 expire; struct para_data_s *para = NULL; @@ -1676,7 +1676,7 @@ generate_keypair( const char *fname ) return; } - algo = ask_algo( 0, &usage ); + algo = ask_algo( 0, &use ); if( !algo ) { /* default: DSA with ElG subkey of the specified size */ both = 1; r = m_alloc_clear( sizeof *r + 20 ); @@ -1705,12 +1705,12 @@ generate_keypair( const char *fname ) r->next = para; para = r; - if (usage) { + if (use) { r = m_alloc_clear( sizeof *r + 20 ); r->key = pKEYUSAGE; sprintf( r->u.value, "%s%s", - (usage & PUBKEY_USAGE_SIG)? "sign ":"", - (usage & PUBKEY_USAGE_ENC)? "encrypt ":"" ); + (use & PUBKEY_USAGE_SIG)? "sign ":"", + (use & PUBKEY_USAGE_ENC)? "encrypt ":"" ); r->next = para; para = r; } @@ -1977,7 +1977,7 @@ generate_subkeypair( KBNODE pub_keyblock, KBNODE sec_keyblock ) KBNODE node; PKT_secret_key *sk = NULL; /* this is the primary sk */ int algo; - unsigned int usage; + unsigned int use; u32 expire; unsigned nbits; char *passphrase = NULL; @@ -2031,7 +2031,7 @@ generate_subkeypair( KBNODE pub_keyblock, KBNODE sec_keyblock ) goto leave; - algo = ask_algo( 1, &usage ); + algo = ask_algo( 1, &use ); assert(algo); nbits = ask_keysize( algo ); expire = ask_expire_interval(); @@ -2050,9 +2050,9 @@ generate_subkeypair( KBNODE pub_keyblock, KBNODE sec_keyblock ) rc = do_create( algo, nbits, pub_keyblock, sec_keyblock, dek, s2k, NULL, expire ); if( !rc ) - rc = write_keybinding(pub_keyblock, pub_keyblock, sk, usage); + rc = write_keybinding(pub_keyblock, pub_keyblock, sk, use); if( !rc ) - rc = write_keybinding(sec_keyblock, pub_keyblock, sk, usage); + rc = write_keybinding(sec_keyblock, pub_keyblock, sk, use); if( !rc ) { okay = 1; write_status_text (STATUS_KEY_CREATED, "S"); diff --git a/g10/keylist.c b/g10/keylist.c index 01f208d8c..29893b489 100644 --- a/g10/keylist.c +++ b/g10/keylist.c @@ -166,12 +166,12 @@ print_key_data( PKT_public_key *pk, u32 *keyid ) static void print_capabilities (PKT_public_key *pk, PKT_secret_key *sk, KBNODE keyblock) { - unsigned int usage = pk? pk->pubkey_usage : sk->pubkey_usage; + unsigned int use = pk? pk->pubkey_usage : sk->pubkey_usage; - if ( usage & PUBKEY_USAGE_ENC ) { + if ( use & PUBKEY_USAGE_ENC ) { putchar ('e'); } - if ( usage & PUBKEY_USAGE_SIG ) { + if ( use & PUBKEY_USAGE_SIG ) { putchar ('s'); putchar ('c'); } diff --git a/g10/keyring.c b/g10/keyring.c index c63f02b84..9186a5ef2 100644 --- a/g10/keyring.c +++ b/g10/keyring.c @@ -795,7 +795,7 @@ keyring_search (KEYRING_HANDLE hd, KEYDB_SEARCH_DESC *desc, size_t ndesc) && desc[n].u.kid[1] == aki[1]) goto found; break; - case KEYDB_SEARCH_MODE_FPR16: break; + case KEYDB_SEARCH_MODE_FPR16: if ((pk||sk) && !memcmp (desc[n].u.fpr, afp, 16)) goto found; break; diff --git a/g10/keyring.o b/g10/keyring.o index e0a98900da8995860081fcd6e89fd1114c63babe..ff1e2ef621bd846318d50510820feb91aaa19f07 100644 GIT binary patch delta 2061 zcmZ9NYfzL`7{{M?4=W4e?s8K@NkCkLyikP7%}{oiB1zOJZ;_4T;1{!W8JmzcTtsl& z8T3S%G09k&Gvy?$+2o}GWyD2d&@v~Z$tjya{K8;irEdR+J-i>XGBwyAvMsJ@{>_pB_9~8wQKVA3HuH92pKfm{Evqh8?`REGitSVSYC}P(ALY? zNh8x=(ujN~2_IkFG+$V(w=~Kd*5SEpw(QB2DQ3GiDl5(D#Zyr>c#*44*tpnJ(@Is5 zo|+c2)U`ot*S(H@^yb(vn=Ey=;0zx8U)f%0*=LS-yHJ{Ak4D`Wu!c7IT(;1>2|UkL z&bug&^1051`D$)|ZRMJW$JPtwvqQV|xjM%3ame30N+U;Hl|u<*WiRrWsx?DVU5=i) z$PRvvKSg;jSS`Cgeh>_Xdphs<95>743d`h-@-r*Fr3Y59_LiH1+e`!Zg27;;qsP;k zw7cC>H|KsZ=&9+UstUQ!l4OqbmLK;zOpRqpLs5-?`P(g#Chf5Q(v&YV+@l7pf{&dN zMTQuUXNXKaP8QGTajGcOW1Fbb<8-k@j~@{pJ)SFe>+wACmL6+jUnq8C;m5@LdLm1F zqQ}{yUym1vU-fvQ7}n!OVpNZFL_*m31>}lcJ^ zkC%$=dR!!GWpmNLw(;%WKy$6irmA@2W};Lo6LD7mN&6`+AueWog%32sSxe;WU_BHg z_c~Lw5_!xyQ+w8b*;#GUJpR(oK;@ARDn%C+OyH1 z)%u%zt0UZ5*oq+o&nc)GiPo~tBN|bDkhy>;7w>~%7SZ#}e4>|`1vm=kVjK&|{Rde; zLG&RLudJW_LZU8}?^XG0%w%%YT@IEI#YclniPD&}iE@}&sE~;TNdL#~X>ch;!C!*rwJJ_k;s*|DL4xuBt#sFaDub;{qs z8jV|-=zEQcz6O=wulTNF3+Ja39Z}lP`bnY-Ow9crbn_Mb$OZ-vFfn+TiNQ(ujpJKW zz{IV24&?d`tZ`*7CI;{xapSQvMp{M{MRG q5l1DX`w!)q@PA9gk6h=x5c?Hren_V(HY|k359iy8t#YvckN*JRhi|k1 delta 2043 zcmYk7eN2^Q7{>4CJm=_9iNlv^N8Awb5csvJVF)S+2h2ud$#Tt9GL=7SLj_w3I~8cs z>1@uYE!T(nM^jtru%kIYw){YYBbBT)XSmq1sY9JhD$5VLE_it7*G*0KhOKT z=e%q^rq3PKThm-u+V-da>QU3oL(fKa$ZQz0&6PRK^mzi&=|jsrYPYG6TddwT=i_Fn ze3Sgxozy}l68T2(iKL8)xRb->abfp~#=G&pcSo4?_!4!&td7qP{R6}G-EYwI9xK@K{B-a{Kc%goEC` z8gIX?IoQ$InzreMDJpG>&&(wbR;HL9+niCi3 zfD_NwQ=Pa_=R0wcE_06>Y@VxMa0S9^0?vrLmEa1A`WzNI`s?gkwWqE4aMAjM=OEweFCa3~4>ui=U@!(Z2mVgSHzzHju)9h7Kl7Y z&JuZ*oGr2rWd8>0IrycL_{|#T3q^L@`aWAfM2?e?Tx3ur@)tQ5XN9wNJt^`8iG|Wg zERX|ofhp7&Tuv5?EF0_zxvlTB^=N-RByx!Xj`t>6B9f3apfgD5 z0upyxL1Lj7Ni0+aa-mh!Sg4M~#y_z69n?XQugPqY<2HYq8vdWj5E?EsD8(~R9vJ8c zU1cJZNHpf#d?7U&7m(;%Oro#a*4J9TVOh_5s>o)m4fQ;cT_oln07JZk!%Sds8;QZ4 zBnAs!e|$7!Nj#cdkp4ny+}R=$gI=-u)zp}?p2Qr!J~`(@tG^&|f-NLY@JI@tKL>ux z1RBp<<5g?CWsP@1`W{fjH+m#AzEl%Ieg|fg7#t)qcmeD1FQSJ3P4XF$EtVgX^F{WJ z#Pet4K_<|63S?s&H5z{>afi2T{*KM}k)lCs0hnx0J*NUblRU z#0JcA2H3zyBsQ=I&RAL?# ty5^B%aV}pubkey_algo, &plain_dek, k->data, sk->skey ); + rc = pubkey_decrypt(sk->pubkey_algo, &plain_dek, enc->data, sk->skey ); if( rc ) goto leave; frame = mpi_get_buffer( plain_dek, &nframe, NULL ); diff --git a/g10/sign.c b/g10/sign.c index 8c9548fc1..cd560aeea 100644 --- a/g10/sign.c +++ b/g10/sign.c @@ -495,7 +495,7 @@ write_signature_packets (SK_LIST sk_list, IOBUF out, MD_HANDLE hash, * make a detached signature. If FILENAMES->d is NULL read from stdin * and ignore the detached mode. Sign the file with all secret keys * which can be taken from LOCUSR, if this is NULL, use the default one - * If ENCRYPT is true, use REMUSER (or ask if it is NULL) to encrypt the + * If ENCRYPTFLAG is true, use REMUSER (or ask if it is NULL) to encrypt the * signed data for these users. * If OUTFILE is not NULL; this file is used for output and the function * does not ask for overwrite permission; output is then always @@ -503,7 +503,7 @@ write_signature_packets (SK_LIST sk_list, IOBUF out, MD_HANDLE hash, */ int sign_file( STRLIST filenames, int detached, STRLIST locusr, - int encrypt, STRLIST remusr, const char *outfile ) + int encryptflag, STRLIST remusr, const char *outfile ) { const char *fname; armor_filter_context_t afx; @@ -536,7 +536,7 @@ sign_file( STRLIST filenames, int detached, STRLIST locusr, else fname = NULL; - if( fname && filenames->next && (!detached || encrypt) ) + if( fname && filenames->next && (!detached || encryptflag) ) log_bug("multiple files can only be detached signed"); if( (rc=build_sk_list( locusr, &sk_list, 1, PUBKEY_USAGE_SIG )) ) @@ -544,7 +544,7 @@ sign_file( STRLIST filenames, int detached, STRLIST locusr, if( !old_style ) old_style = only_old_style( sk_list ); - if( encrypt ) { + if( encryptflag ) { if( (rc=build_pk_list( remusr, &pk_list, PUBKEY_USAGE_ENC )) ) goto leave; if( !old_style ) @@ -586,13 +586,13 @@ sign_file( STRLIST filenames, int detached, STRLIST locusr, if( !multifile ) iobuf_push_filter( inp, md_filter, &mfx ); - if( detached && !encrypt && !opt.rfc1991 ) + if( detached && !encryptflag && !opt.rfc1991 ) afx.what = 2; if( opt.armor && !outfile ) iobuf_push_filter( out, armor_filter, &afx ); - if( encrypt ) { + if( encryptflag ) { efx.pk_list = pk_list; /* fixme: set efx.cfx.datalen if known */ iobuf_push_filter( out, encrypt_filter, &efx ); @@ -604,7 +604,7 @@ sign_file( STRLIST filenames, int detached, STRLIST locusr, else { if( old_style || compr_algo == 1 - || (compr_algo == -1 && !encrypt) ) + || (compr_algo == -1 && !encryptflag) ) zfx.algo = 1; /* use the non optional algorithm */ iobuf_push_filter( out, compress_filter, &zfx ); } @@ -672,7 +672,7 @@ sign_file( STRLIST filenames, int detached, STRLIST locusr, iobuf_cancel(out); else { iobuf_close(out); - if (encrypt) + if (encryptflag) write_status( STATUS_END_ENCRYPTION ); } iobuf_close(inp); diff --git a/include/ChangeLog b/include/ChangeLog index a591c9136..513b036a0 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,7 @@ +2001-09-07 Werner Koch + + * util.h: Add strsep(). + 2001-08-30 Werner Koch * cipher.h (DEK): Added use_mdc. diff --git a/include/util.h b/include/util.h index aa2d90594..eafcabcf4 100644 --- a/include/util.h +++ b/include/util.h @@ -203,6 +203,9 @@ char *stpcpy(char *a,const char *b); #ifndef HAVE_STRLWR char *strlwr(char *a); #endif +#ifndef HAVE_STRSEP +char *strsep (char **stringp, const char *delim); +#endif #ifndef HAVE_STRCASECMP int strcasecmp( const char *, const char *b); #endif diff --git a/util/ChangeLog b/util/ChangeLog index ccbe1764b..7097e9125 100644 --- a/util/ChangeLog +++ b/util/ChangeLog @@ -1,3 +1,7 @@ +2001-09-07 Werner Koch + + * strgutil.c (strsep): New, taken from glibc 2.2.1. + 2001-09-03 Werner Koch * miscutil.c (strtimestamp,asctimestamp): Avoid trigraphs. diff --git a/util/strgutil.c b/util/strgutil.c index 4bae35e32..5e978eb04 100644 --- a/util/strgutil.c +++ b/util/strgutil.c @@ -689,6 +689,56 @@ stpcpy(char *a,const char *b) } #endif + +#ifndef HAVE_STRSEP +/* code taken from glibc-2.2.1/sysdeps/generic/strsep.c */ +char * +strsep (char **stringp, const char *delim) +{ + char *begin, *end; + + begin = *stringp; + if (begin == NULL) + return NULL; + + /* A frequent case is when the delimiter string contains only one + character. Here we don't need to call the expensive `strpbrk' + function and instead work using `strchr'. */ + if (delim[0] == '\0' || delim[1] == '\0') + { + char ch = delim[0]; + + if (ch == '\0') + end = NULL; + else + { + if (*begin == ch) + end = begin; + else if (*begin == '\0') + end = NULL; + else + end = strchr (begin + 1, ch); + } + } + else + /* Find the end of the token. */ + end = strpbrk (begin, delim); + + if (end) + { + /* Terminate the token and set *STRINGP past NUL character. */ + *end++ = '\0'; + *stringp = end; + } + else + /* No more delimiters; this is the last token. */ + *stringp = NULL; + + return begin; +} +#endif /*HAVE_STRSEP*/ + + #ifndef HAVE_STRLWR char * strlwr(char *s) @@ -823,4 +873,3 @@ vasprintf ( char **result, const char *format, va_list args) #endif /*__MINGW32__*/ -