diff options
author | millert <> | 2002-02-18 21:40:46 +0000 |
---|---|---|
committer | millert <> | 2002-02-18 21:40:46 +0000 |
commit | 97ec74faebf84f0ecbbf3706ec05647d012003c9 (patch) | |
tree | cc860027384907afd40fcda31c43c650a1cc3335 /src | |
parent | 060915427244cdc729e277e4691f6bdd42c34a49 (diff) | |
download | openbsd-97ec74faebf84f0ecbbf3706ec05647d012003c9.tar.gz openbsd-97ec74faebf84f0ecbbf3706ec05647d012003c9.tar.bz2 openbsd-97ec74faebf84f0ecbbf3706ec05647d012003c9.zip |
Rename private err() function to dberr() to avoid collision with
libc's err().
Diffstat (limited to 'src')
-rw-r--r-- | src/regress/lib/libc/db/dbtest.c | 91 |
1 files changed, 49 insertions, 42 deletions
diff --git a/src/regress/lib/libc/db/dbtest.c b/src/regress/lib/libc/db/dbtest.c index 9f4da58800..53451c5438 100644 --- a/src/regress/lib/libc/db/dbtest.c +++ b/src/regress/lib/libc/db/dbtest.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: dbtest.c,v 1.7 2002/02/16 21:27:32 millert Exp $ */ | 1 | /* $OpenBSD: dbtest.c,v 1.8 2002/02/18 21:40:46 millert Exp $ */ |
2 | /* $NetBSD: dbtest.c,v 1.8 1996/05/03 21:57:48 cgd Exp $ */ | 2 | /* $NetBSD: dbtest.c,v 1.8 1996/05/03 21:57:48 cgd Exp $ */ |
3 | 3 | ||
4 | /*- | 4 | /*- |
@@ -44,7 +44,7 @@ static char copyright[] = | |||
44 | #if 0 | 44 | #if 0 |
45 | static char sccsid[] = "@(#)dbtest.c 8.17 (Berkeley) 9/1/94"; | 45 | static char sccsid[] = "@(#)dbtest.c 8.17 (Berkeley) 9/1/94"; |
46 | #else | 46 | #else |
47 | static char rcsid[] = "$OpenBSD: dbtest.c,v 1.7 2002/02/16 21:27:32 millert Exp $"; | 47 | static char rcsid[] = "$OpenBSD: dbtest.c,v 1.8 2002/02/18 21:40:46 millert Exp $"; |
48 | #endif | 48 | #endif |
49 | #endif /* not lint */ | 49 | #endif /* not lint */ |
50 | 50 | ||
@@ -67,7 +67,7 @@ enum S { COMMAND, COMPARE, GET, PUT, REMOVE, SEQ, SEQFLAG, KEY, DATA }; | |||
67 | void compare(DBT *, DBT *); | 67 | void compare(DBT *, DBT *); |
68 | DBTYPE dbtype(char *); | 68 | DBTYPE dbtype(char *); |
69 | void dump(DB *, int); | 69 | void dump(DB *, int); |
70 | void err(const char *, ...); | 70 | void dberr(const char *, ...); |
71 | void get(DB *, DBT *); | 71 | void get(DB *, DBT *); |
72 | void getdata(DB *, DBT *, DBT *); | 72 | void getdata(DB *, DBT *, DBT *); |
73 | void put(DB *, DBT *, DBT *); | 73 | void put(DB *, DBT *, DBT *); |
@@ -122,7 +122,7 @@ main(argc, argv) | |||
122 | case 'o': | 122 | case 'o': |
123 | if ((ofd = open(optarg, | 123 | if ((ofd = open(optarg, |
124 | O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) | 124 | O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) |
125 | err("%s: %s", optarg, strerror(errno)); | 125 | dberr("%s: %s", optarg, strerror(errno)); |
126 | break; | 126 | break; |
127 | case 's': | 127 | case 's': |
128 | sflag = 1; | 128 | sflag = 1; |
@@ -142,7 +142,7 @@ main(argc, argv) | |||
142 | 142 | ||
143 | /* Open the descriptor file. */ | 143 | /* Open the descriptor file. */ |
144 | if (strcmp(*argv, "-") && freopen(*argv, "r", stdin) == NULL) | 144 | if (strcmp(*argv, "-") && freopen(*argv, "r", stdin) == NULL) |
145 | err("%s: %s", *argv, strerror(errno)); | 145 | dberr("%s: %s", *argv, strerror(errno)); |
146 | 146 | ||
147 | /* Set up the db structure as necessary. */ | 147 | /* Set up the db structure as necessary. */ |
148 | if (infoarg == NULL) | 148 | if (infoarg == NULL) |
@@ -169,7 +169,7 @@ main(argc, argv) | |||
169 | 169 | ||
170 | if ((dbp = dbopen(fname, | 170 | if ((dbp = dbopen(fname, |
171 | oflags, S_IRUSR | S_IWUSR, type, infop)) == NULL) | 171 | oflags, S_IRUSR | S_IWUSR, type, infop)) == NULL) |
172 | err("dbopen: %s", strerror(errno)); | 172 | dberr("dbopen: %s", strerror(errno)); |
173 | XXdbp = dbp; | 173 | XXdbp = dbp; |
174 | 174 | ||
175 | state = COMMAND; | 175 | state = COMMAND; |
@@ -187,35 +187,40 @@ main(argc, argv) | |||
187 | switch (*p) { | 187 | switch (*p) { |
188 | case 'c': /* compare */ | 188 | case 'c': /* compare */ |
189 | if (state != COMMAND) | 189 | if (state != COMMAND) |
190 | err("line %lu: not expecting command", lineno); | 190 | dberr("line %lu: not expecting command", |
191 | lineno); | ||
191 | state = KEY; | 192 | state = KEY; |
192 | command = COMPARE; | 193 | command = COMPARE; |
193 | break; | 194 | break; |
194 | case 'e': /* echo */ | 195 | case 'e': /* echo */ |
195 | if (state != COMMAND) | 196 | if (state != COMMAND) |
196 | err("line %lu: not expecting command", lineno); | 197 | dberr("line %lu: not expecting command", |
198 | lineno); | ||
197 | /* Don't display the newline, if CR at EOL. */ | 199 | /* Don't display the newline, if CR at EOL. */ |
198 | if (p[len - 2] == '\r') | 200 | if (p[len - 2] == '\r') |
199 | --len; | 201 | --len; |
200 | if (write(ofd, p + 1, len - 1) != len - 1 || | 202 | if (write(ofd, p + 1, len - 1) != len - 1 || |
201 | write(ofd, "\n", 1) != 1) | 203 | write(ofd, "\n", 1) != 1) |
202 | err("write: %s", strerror(errno)); | 204 | dberr("write: %s", strerror(errno)); |
203 | break; | 205 | break; |
204 | case 'g': /* get */ | 206 | case 'g': /* get */ |
205 | if (state != COMMAND) | 207 | if (state != COMMAND) |
206 | err("line %lu: not expecting command", lineno); | 208 | dberr("line %lu: not expecting command", |
209 | lineno); | ||
207 | state = KEY; | 210 | state = KEY; |
208 | command = GET; | 211 | command = GET; |
209 | break; | 212 | break; |
210 | case 'p': /* put */ | 213 | case 'p': /* put */ |
211 | if (state != COMMAND) | 214 | if (state != COMMAND) |
212 | err("line %lu: not expecting command", lineno); | 215 | dberr("line %lu: not expecting command", |
216 | lineno); | ||
213 | state = KEY; | 217 | state = KEY; |
214 | command = PUT; | 218 | command = PUT; |
215 | break; | 219 | break; |
216 | case 'r': /* remove */ | 220 | case 'r': /* remove */ |
217 | if (state != COMMAND) | 221 | if (state != COMMAND) |
218 | err("line %lu: not expecting command", lineno); | 222 | dberr("line %lu: not expecting command", |
223 | lineno); | ||
219 | if (flags == R_CURSOR) { | 224 | if (flags == R_CURSOR) { |
220 | rem(dbp, &key); | 225 | rem(dbp, &key); |
221 | state = COMMAND; | 226 | state = COMMAND; |
@@ -226,13 +231,15 @@ main(argc, argv) | |||
226 | break; | 231 | break; |
227 | case 'S': /* sync */ | 232 | case 'S': /* sync */ |
228 | if (state != COMMAND) | 233 | if (state != COMMAND) |
229 | err("line %lu: not expecting command", lineno); | 234 | dberr("line %lu: not expecting command", |
235 | lineno); | ||
230 | synk(dbp); | 236 | synk(dbp); |
231 | state = COMMAND; | 237 | state = COMMAND; |
232 | break; | 238 | break; |
233 | case 's': /* seq */ | 239 | case 's': /* seq */ |
234 | if (state != COMMAND) | 240 | if (state != COMMAND) |
235 | err("line %lu: not expecting command", lineno); | 241 | dberr("line %lu: not expecting command", |
242 | lineno); | ||
236 | if (flags == R_CURSOR) { | 243 | if (flags == R_CURSOR) { |
237 | state = KEY; | 244 | state = KEY; |
238 | command = SEQ; | 245 | command = SEQ; |
@@ -244,12 +251,12 @@ main(argc, argv) | |||
244 | break; | 251 | break; |
245 | case 'D': /* data file */ | 252 | case 'D': /* data file */ |
246 | if (state != DATA) | 253 | if (state != DATA) |
247 | err("line %lu: not expecting data", lineno); | 254 | dberr("line %lu: not expecting data", lineno); |
248 | data.data = rfile(p + 1, &data.size); | 255 | data.data = rfile(p + 1, &data.size); |
249 | goto ldata; | 256 | goto ldata; |
250 | case 'd': /* data */ | 257 | case 'd': /* data */ |
251 | if (state != DATA) | 258 | if (state != DATA) |
252 | err("line %lu: not expecting data", lineno); | 259 | dberr("line %lu: not expecting data", lineno); |
253 | data.data = xmalloc(p + 1, len - 1); | 260 | data.data = xmalloc(p + 1, len - 1); |
254 | data.size = len - 1; | 261 | data.size = len - 1; |
255 | ldata: switch (command) { | 262 | ldata: switch (command) { |
@@ -260,7 +267,7 @@ ldata: switch (command) { | |||
260 | put(dbp, &key, &data); | 267 | put(dbp, &key, &data); |
261 | break; | 268 | break; |
262 | default: | 269 | default: |
263 | err("line %lu: command doesn't take data", | 270 | dberr("line %lu: command doesn't take data", |
264 | lineno); | 271 | lineno); |
265 | } | 272 | } |
266 | if (type != DB_RECNO) | 273 | if (type != DB_RECNO) |
@@ -270,15 +277,15 @@ ldata: switch (command) { | |||
270 | break; | 277 | break; |
271 | case 'K': /* key file */ | 278 | case 'K': /* key file */ |
272 | if (state != KEY) | 279 | if (state != KEY) |
273 | err("line %lu: not expecting a key", lineno); | 280 | dberr("line %lu: not expecting a key", lineno); |
274 | if (type == DB_RECNO) | 281 | if (type == DB_RECNO) |
275 | err("line %lu: 'K' not available for recno", | 282 | dberr("line %lu: 'K' not available for recno", |
276 | lineno); | 283 | lineno); |
277 | key.data = rfile(p + 1, &key.size); | 284 | key.data = rfile(p + 1, &key.size); |
278 | goto lkey; | 285 | goto lkey; |
279 | case 'k': /* key */ | 286 | case 'k': /* key */ |
280 | if (state != KEY) | 287 | if (state != KEY) |
281 | err("line %lu: not expecting a key", lineno); | 288 | dberr("line %lu: not expecting a key", lineno); |
282 | if (type == DB_RECNO) { | 289 | if (type == DB_RECNO) { |
283 | static recno_t recno; | 290 | static recno_t recno; |
284 | recno = atoi(p + 1); | 291 | recno = atoi(p + 1); |
@@ -315,7 +322,7 @@ lkey: switch (command) { | |||
315 | state = COMMAND; | 322 | state = COMMAND; |
316 | break; | 323 | break; |
317 | default: | 324 | default: |
318 | err("line %lu: command doesn't take a key", | 325 | dberr("line %lu: command doesn't take a key", |
319 | lineno); | 326 | lineno); |
320 | } | 327 | } |
321 | break; | 328 | break; |
@@ -323,7 +330,7 @@ lkey: switch (command) { | |||
323 | dump(dbp, p[1] == 'r'); | 330 | dump(dbp, p[1] == 'r'); |
324 | break; | 331 | break; |
325 | default: | 332 | default: |
326 | err("line %lu: %s: unknown command character", | 333 | dberr("line %lu: %s: unknown command character", |
327 | lineno, p); | 334 | lineno, p); |
328 | } | 335 | } |
329 | } | 336 | } |
@@ -336,7 +343,7 @@ lkey: switch (command) { | |||
336 | __bt_stat(dbp); | 343 | __bt_stat(dbp); |
337 | #endif | 344 | #endif |
338 | if (dbp->close(dbp)) | 345 | if (dbp->close(dbp)) |
339 | err("db->close: %s", strerror(errno)); | 346 | dberr("db->close: %s", strerror(errno)); |
340 | (void)close(ofd); | 347 | (void)close(ofd); |
341 | exit(0); | 348 | exit(0); |
342 | } | 349 | } |
@@ -377,7 +384,7 @@ get(dbp, kp) | |||
377 | (void)write(ofd, "\n", 1); | 384 | (void)write(ofd, "\n", 1); |
378 | break; | 385 | break; |
379 | case -1: | 386 | case -1: |
380 | err("line %lu: get: %s", lineno, strerror(errno)); | 387 | dberr("line %lu: get: %s", lineno, strerror(errno)); |
381 | /* NOTREACHED */ | 388 | /* NOTREACHED */ |
382 | case 1: | 389 | case 1: |
383 | #define NOSUCHKEY "get failed, no such key\n" | 390 | #define NOSUCHKEY "get failed, no such key\n" |
@@ -400,10 +407,10 @@ getdata(dbp, kp, dp) | |||
400 | case 0: | 407 | case 0: |
401 | return; | 408 | return; |
402 | case -1: | 409 | case -1: |
403 | err("line %lu: getdata: %s", lineno, strerror(errno)); | 410 | dberr("line %lu: getdata: %s", lineno, strerror(errno)); |
404 | /* NOTREACHED */ | 411 | /* NOTREACHED */ |
405 | case 1: | 412 | case 1: |
406 | err("line %lu: getdata failed, no such key", lineno); | 413 | dberr("line %lu: getdata failed, no such key", lineno); |
407 | /* NOTREACHED */ | 414 | /* NOTREACHED */ |
408 | } | 415 | } |
409 | } | 416 | } |
@@ -417,7 +424,7 @@ put(dbp, kp, dp) | |||
417 | case 0: | 424 | case 0: |
418 | break; | 425 | break; |
419 | case -1: | 426 | case -1: |
420 | err("line %lu: put: %s", lineno, strerror(errno)); | 427 | dberr("line %lu: put: %s", lineno, strerror(errno)); |
421 | /* NOTREACHED */ | 428 | /* NOTREACHED */ |
422 | case 1: | 429 | case 1: |
423 | (void)write(ofd, NOOVERWRITE, sizeof(NOOVERWRITE) - 1); | 430 | (void)write(ofd, NOOVERWRITE, sizeof(NOOVERWRITE) - 1); |
@@ -434,7 +441,7 @@ rem(dbp, kp) | |||
434 | case 0: | 441 | case 0: |
435 | break; | 442 | break; |
436 | case -1: | 443 | case -1: |
437 | err("line %lu: rem: %s", lineno, strerror(errno)); | 444 | dberr("line %lu: rem: %s", lineno, strerror(errno)); |
438 | /* NOTREACHED */ | 445 | /* NOTREACHED */ |
439 | case 1: | 446 | case 1: |
440 | #define NOSUCHKEY "rem failed, no such key\n" | 447 | #define NOSUCHKEY "rem failed, no such key\n" |
@@ -459,7 +466,7 @@ synk(dbp) | |||
459 | case 0: | 466 | case 0: |
460 | break; | 467 | break; |
461 | case -1: | 468 | case -1: |
462 | err("line %lu: synk: %s", lineno, strerror(errno)); | 469 | dberr("line %lu: synk: %s", lineno, strerror(errno)); |
463 | /* NOTREACHED */ | 470 | /* NOTREACHED */ |
464 | } | 471 | } |
465 | } | 472 | } |
@@ -478,7 +485,7 @@ seq(dbp, kp) | |||
478 | (void)write(ofd, "\n", 1); | 485 | (void)write(ofd, "\n", 1); |
479 | break; | 486 | break; |
480 | case -1: | 487 | case -1: |
481 | err("line %lu: seq: %s", lineno, strerror(errno)); | 488 | dberr("line %lu: seq: %s", lineno, strerror(errno)); |
482 | /* NOTREACHED */ | 489 | /* NOTREACHED */ |
483 | case 1: | 490 | case 1: |
484 | #define NOSUCHKEY "seq failed, no such key\n" | 491 | #define NOSUCHKEY "seq failed, no such key\n" |
@@ -520,7 +527,7 @@ dump(dbp, rev) | |||
520 | case 1: | 527 | case 1: |
521 | goto done; | 528 | goto done; |
522 | case -1: | 529 | case -1: |
523 | err("line %lu: (dump) seq: %s", | 530 | dberr("line %lu: (dump) seq: %s", |
524 | lineno, strerror(errno)); | 531 | lineno, strerror(errno)); |
525 | /* NOTREACHED */ | 532 | /* NOTREACHED */ |
526 | } | 533 | } |
@@ -548,7 +555,7 @@ setflags(s) | |||
548 | if (!strcmp(s, "R_PREV")) return (R_PREV); | 555 | if (!strcmp(s, "R_PREV")) return (R_PREV); |
549 | if (!strcmp(s, "R_SETCURSOR")) return (R_SETCURSOR); | 556 | if (!strcmp(s, "R_SETCURSOR")) return (R_SETCURSOR); |
550 | 557 | ||
551 | err("line %lu: %s: unknown flag", lineno, s); | 558 | dberr("line %lu: %s: unknown flag", lineno, s); |
552 | /* NOTREACHED */ | 559 | /* NOTREACHED */ |
553 | } | 560 | } |
554 | 561 | ||
@@ -581,7 +588,7 @@ dbtype(s) | |||
581 | return (DB_HASH); | 588 | return (DB_HASH); |
582 | if (!strcmp(s, "recno")) | 589 | if (!strcmp(s, "recno")) |
583 | return (DB_RECNO); | 590 | return (DB_RECNO); |
584 | err("%s: unknown type (use btree, hash or recno)", s); | 591 | dberr("%s: unknown type (use btree, hash or recno)", s); |
585 | /* NOTREACHED */ | 592 | /* NOTREACHED */ |
586 | } | 593 | } |
587 | 594 | ||
@@ -596,10 +603,10 @@ setinfo(type, s) | |||
596 | char *eq; | 603 | char *eq; |
597 | 604 | ||
598 | if ((eq = strchr(s, '=')) == NULL) | 605 | if ((eq = strchr(s, '=')) == NULL) |
599 | err("%s: illegal structure set statement", s); | 606 | dberr("%s: illegal structure set statement", s); |
600 | *eq++ = '\0'; | 607 | *eq++ = '\0'; |
601 | if (!isdigit(*eq)) | 608 | if (!isdigit(*eq)) |
602 | err("%s: structure set statement must be a number", s); | 609 | dberr("%s: structure set statement must be a number", s); |
603 | 610 | ||
604 | switch (type) { | 611 | switch (type) { |
605 | case DB_BTREE: | 612 | case DB_BTREE: |
@@ -677,7 +684,7 @@ setinfo(type, s) | |||
677 | } | 684 | } |
678 | break; | 685 | break; |
679 | } | 686 | } |
680 | err("%s: unknown structure value", s); | 687 | dberr("%s: unknown structure value", s); |
681 | /* NOTREACHED */ | 688 | /* NOTREACHED */ |
682 | } | 689 | } |
683 | 690 | ||
@@ -696,13 +703,13 @@ rfile(name, lenp) | |||
696 | *np = '\0'; | 703 | *np = '\0'; |
697 | if ((fd = open(name, O_RDONLY, 0)) < 0 || | 704 | if ((fd = open(name, O_RDONLY, 0)) < 0 || |
698 | fstat(fd, &sb)) | 705 | fstat(fd, &sb)) |
699 | err("%s: %s\n", name, strerror(errno)); | 706 | dberr("%s: %s\n", name, strerror(errno)); |
700 | #ifdef NOT_PORTABLE | 707 | #ifdef NOT_PORTABLE |
701 | if (sb.st_size > (off_t)SIZE_T_MAX) | 708 | if (sb.st_size > (off_t)SIZE_T_MAX) |
702 | err("%s: %s\n", name, strerror(E2BIG)); | 709 | dberr("%s: %s\n", name, strerror(E2BIG)); |
703 | #endif | 710 | #endif |
704 | if ((p = (void *)malloc((u_int)sb.st_size)) == NULL) | 711 | if ((p = (void *)malloc((u_int)sb.st_size)) == NULL) |
705 | err("%s", strerror(errno)); | 712 | dberr("%s", strerror(errno)); |
706 | (void)read(fd, p, (int)sb.st_size); | 713 | (void)read(fd, p, (int)sb.st_size); |
707 | *lenp = sb.st_size; | 714 | *lenp = sb.st_size; |
708 | (void)close(fd); | 715 | (void)close(fd); |
@@ -717,7 +724,7 @@ xmalloc(text, len) | |||
717 | void *p; | 724 | void *p; |
718 | 725 | ||
719 | if ((p = (void *)malloc(len)) == NULL) | 726 | if ((p = (void *)malloc(len)) == NULL) |
720 | err("%s", strerror(errno)); | 727 | dberr("%s", strerror(errno)); |
721 | memmove(p, text, len); | 728 | memmove(p, text, len); |
722 | return (p); | 729 | return (p); |
723 | } | 730 | } |
@@ -738,9 +745,9 @@ usage() | |||
738 | 745 | ||
739 | void | 746 | void |
740 | #ifdef __STDC__ | 747 | #ifdef __STDC__ |
741 | err(const char *fmt, ...) | 748 | dberr(const char *fmt, ...) |
742 | #else | 749 | #else |
743 | err(fmt, va_alist) | 750 | dberr(fmt, va_alist) |
744 | char *fmt; | 751 | char *fmt; |
745 | va_dcl | 752 | va_dcl |
746 | #endif | 753 | #endif |