1/* |
2 * Copyright (c) 1997-2003 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 * --- 22 unchanged lines hidden (view full) --- 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 * |
41 * $Id: mk-amd-map.c,v 1.5.2.5 2003/06/09 16:57:46 ezk Exp $ 42 * $FreeBSD: head/contrib/amd/mk-amd-map/mk-amd-map.c 119682 2003-09-02 15:42:57Z mbr $ |
43 */ 44 45/* 46 * Convert a file map into an ndbm map 47 */ 48 49#ifdef HAVE_CONFIG_H 50# include <config.h> --- 231 unchanged lines hidden (view full) --- 282 map_name_dir = (char *) malloc(len + 5); 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 291 { 292 /* 293 * XXX: hack to avoid compiler complaints about mktemp not being 294 * secure, since we have to do a dbm_open on this anyway. So use 295 * mkstemp if you can, and then close the fd, but we get a safe 296 * and unique file name. 297 */ 298 int dummyfd; 299 dummyfd = mkstemp(maptmp); 300 if (dummyfd >= 0) 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 309 sprintf(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 */ 316 sprintf(maptpag, "%s.pag", maptmp); 317 sprintf(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); |
326 if (!db) { 327 fprintf(stderr, "cannot initialize temporary database: %s", maptmp); 328 exit(1); 329 } 330 } 331 332 /* print db to stdout or to temp database */ 333 error = read_file(mapf, mapsrc, db); --- 65 unchanged lines hidden --- |