mk-amd-map.c (131706) | mk-amd-map.c (174313) |
---|---|
1/* | 1/* |
2 * Copyright (c) 1997-2004 Erez Zadok | 2 * Copyright (c) 1997-2006 Erez Zadok |
3 * Copyright (c) 1990 Jan-Simon Pendry 4 * Copyright (c) 1990 Imperial College of Science, Technology & Medicine 5 * Copyright (c) 1990 The Regents of the University of California. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * Jan-Simon Pendry at Imperial College, London. 10 * --- 20 unchanged lines hidden (view full) --- 31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 * | 3 * Copyright (c) 1990 Jan-Simon Pendry 4 * Copyright (c) 1990 Imperial College of Science, Technology & Medicine 5 * Copyright (c) 1990 The Regents of the University of California. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * Jan-Simon Pendry at Imperial College, London. 10 * --- 20 unchanged lines hidden (view full) --- 31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 * |
39 * %W% (Berkeley) %G% | |
40 * | 39 * |
41 * $Id: mk-amd-map.c,v 1.5.2.6 2004/01/06 03:15:25 ezk Exp $ 42 * $FreeBSD: head/contrib/amd/mk-amd-map/mk-amd-map.c 131706 2004-07-06 13:16:49Z mbr $ | 40 * File: am-utils/mk-amd-map/mk-amd-map.c |
43 */ 44 45/* 46 * Convert a file map into an ndbm map 47 */ 48 49#ifdef HAVE_CONFIG_H 50# include <config.h> --- 168 unchanged lines hidden (view full) --- 219 static char maptmp[] = "dbmXXXXXX"; 220#ifdef HAVE_DB_SUFFIX 221 char maptdb[16]; 222 char *map_name_db = (char *) NULL; 223#else /* not HAVE_DB_SUFFIX */ 224 char maptpag[16], maptdir[16]; 225 char *map_name_pag = (char *) NULL, *map_name_dir = (char *) NULL; 226#endif /* not HAVE_DB_SUFFIX */ | 41 */ 42 43/* 44 * Convert a file map into an ndbm map 45 */ 46 47#ifdef HAVE_CONFIG_H 48# include <config.h> --- 168 unchanged lines hidden (view full) --- 217 static char maptmp[] = "dbmXXXXXX"; 218#ifdef HAVE_DB_SUFFIX 219 char maptdb[16]; 220 char *map_name_db = (char *) NULL; 221#else /* not HAVE_DB_SUFFIX */ 222 char maptpag[16], maptdir[16]; 223 char *map_name_pag = (char *) NULL, *map_name_dir = (char *) NULL; 224#endif /* not HAVE_DB_SUFFIX */ |
227 int len; | 225 size_t l = 0; |
228 char *sl; 229 int printit = 0; 230 int usage = 0; 231 int ch; 232 extern int optind; 233 234 /* test options */ 235 while ((ch = getopt(argc, argv, "p")) != -1) --- 32 unchanged lines hidden (view full) --- 268 exit(1); 269 } 270 271#ifndef DEBUG 272 signal(SIGINT, SIG_IGN); 273#endif /* DEBUG */ 274 275 if (!printit) { | 226 char *sl; 227 int printit = 0; 228 int usage = 0; 229 int ch; 230 extern int optind; 231 232 /* test options */ 233 while ((ch = getopt(argc, argv, "p")) != -1) --- 32 unchanged lines hidden (view full) --- 266 exit(1); 267 } 268 269#ifndef DEBUG 270 signal(SIGINT, SIG_IGN); 271#endif /* DEBUG */ 272 273 if (!printit) { |
276 len = strlen(mapsrc); | 274 /* enough space for ".db" or ".pag" or ".dir" appended */ 275 l = strlen(mapsrc) + 5; |
277#ifdef HAVE_DB_SUFFIX | 276#ifdef HAVE_DB_SUFFIX |
278 map_name_db = (char *) malloc(len + 4); | 277 map_name_db = (char *) malloc(l); |
279 error = (map_name_db == NULL); 280#else /* not HAVE_DB_SUFFIX */ | 278 error = (map_name_db == NULL); 279#else /* not HAVE_DB_SUFFIX */ |
281 map_name_pag = (char *) malloc(len + 5); 282 map_name_dir = (char *) malloc(len + 5); | 280 map_name_pag = (char *) malloc(l); 281 map_name_dir = (char *) malloc(l); |
283 error = (map_name_pag == NULL || map_name_dir == NULL); 284#endif /* not HAVE_DB_SUFFIX */ 285 if (error) { 286 perror("mk-amd-map: malloc"); 287 exit(1); 288 } 289 290#ifdef HAVE_MKSTEMP --- 10 unchanged lines hidden (view full) --- 301 close(dummyfd); 302 } 303#else /* not HAVE_MKSTEMP */ 304 mktemp(maptmp); 305#endif /* not HAVE_MKSTEMP */ 306 307 /* remove existing temps (if any) */ 308#ifdef HAVE_DB_SUFFIX | 282 error = (map_name_pag == NULL || map_name_dir == NULL); 283#endif /* not HAVE_DB_SUFFIX */ 284 if (error) { 285 perror("mk-amd-map: malloc"); 286 exit(1); 287 } 288 289#ifdef HAVE_MKSTEMP --- 10 unchanged lines hidden (view full) --- 300 close(dummyfd); 301 } 302#else /* not HAVE_MKSTEMP */ 303 mktemp(maptmp); 304#endif /* not HAVE_MKSTEMP */ 305 306 /* remove existing temps (if any) */ 307#ifdef HAVE_DB_SUFFIX |
309 sprintf(maptdb, "%s.db", maptmp); | 308 xsnprintf(maptdb, sizeof(maptdb), "%s.db", maptmp); |
310 if (remove_file(maptdb) < 0) { 311 fprintf(stderr, "Can't remove existing temporary file; "); 312 perror(maptdb); 313 exit(1); 314 } 315#else /* not HAVE_DB_SUFFIX */ | 309 if (remove_file(maptdb) < 0) { 310 fprintf(stderr, "Can't remove existing temporary file; "); 311 perror(maptdb); 312 exit(1); 313 } 314#else /* not HAVE_DB_SUFFIX */ |
316 sprintf(maptpag, "%s.pag", maptmp); 317 sprintf(maptdir, "%s.dir", maptmp); | 315 xsnprintf(maptpag, sizeof(maptpag), "%s.pag", maptmp); 316 xsnprintf(maptdir, sizeof(maptdir), "%s.dir", maptmp); |
318 if (remove_file(maptpag) < 0 || remove_file(maptdir) < 0) { 319 fprintf(stderr, "Can't remove existing temporary files; %s and ", maptpag); 320 perror(maptdir); 321 exit(1); 322 } 323#endif /* not HAVE_DB_SUFFIX */ 324 325 db = dbm_open(maptmp, O_RDWR|O_CREAT|O_EXCL, 0444); --- 18 unchanged lines hidden (view full) --- 344 exit(0); /* nothing more to do */ 345 346 /* if gets here, we wrote to a database */ 347 348 dbm_close(db); 349 /* all went well */ 350 351#ifdef HAVE_DB_SUFFIX | 317 if (remove_file(maptpag) < 0 || remove_file(maptdir) < 0) { 318 fprintf(stderr, "Can't remove existing temporary files; %s and ", maptpag); 319 perror(maptdir); 320 exit(1); 321 } 322#endif /* not HAVE_DB_SUFFIX */ 323 324 db = dbm_open(maptmp, O_RDWR|O_CREAT|O_EXCL, 0444); --- 18 unchanged lines hidden (view full) --- 343 exit(0); /* nothing more to do */ 344 345 /* if gets here, we wrote to a database */ 346 347 dbm_close(db); 348 /* all went well */ 349 350#ifdef HAVE_DB_SUFFIX |
352 sprintf(map_name_db, "%s.db", mapsrc); | 351 /* sizeof(map_name_db) is malloc'ed above */ 352 xsnprintf(map_name_db, l, "%s.db", mapsrc); |
353 if (rename(maptdb, map_name_db) < 0) { 354 fprintf(stderr, "Couldn't rename %s to ", maptdb); 355 perror(map_name_db); 356 /* Throw away the temporary map */ 357 unlink(maptdb); 358 exit(1); 359 } 360#else /* not HAVE_DB_SUFFIX */ | 353 if (rename(maptdb, map_name_db) < 0) { 354 fprintf(stderr, "Couldn't rename %s to ", maptdb); 355 perror(map_name_db); 356 /* Throw away the temporary map */ 357 unlink(maptdb); 358 exit(1); 359 } 360#else /* not HAVE_DB_SUFFIX */ |
361 sprintf(map_name_pag, "%s.pag", mapsrc); 362 sprintf(map_name_dir, "%s.dir", mapsrc); | 361 /* sizeof(map_name_{pag,dir}) are malloc'ed above */ 362 xsnprintf(map_name_pag, l, "%s.pag", mapsrc); 363 xsnprintf(map_name_dir, l, "%s.dir", mapsrc); |
363 if (rename(maptpag, map_name_pag) < 0) { 364 fprintf(stderr, "Couldn't rename %s to ", maptpag); 365 perror(map_name_pag); 366 /* Throw away the temporary map */ 367 unlink(maptpag); 368 unlink(maptdir); 369 exit(1); 370 } --- 28 unchanged lines hidden --- | 364 if (rename(maptpag, map_name_pag) < 0) { 365 fprintf(stderr, "Couldn't rename %s to ", maptpag); 366 perror(map_name_pag); 367 /* Throw away the temporary map */ 368 unlink(maptpag); 369 unlink(maptdir); 370 exit(1); 371 } --- 28 unchanged lines hidden --- |