1N/A/*********************************************************************** 1N/A* This software is part of the ast package * 1N/A* Copyright (c) 1985-2011 AT&T Intellectual Property * 1N/A* and is licensed under the * 1N/A* Common Public License, Version 1.0 * 1N/A* by AT&T Intellectual Property * 1N/A* A copy of the License is available at * 1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 1N/A* Information and Software Systems Research * 1N/A* Glenn Fowler <gsf@research.att.com> * 1N/A* David Korn <dgk@research.att.com> * 1N/A* Phong Vo <kpv@research.att.com> * 1N/A***********************************************************************/ 1N/A** The stream is originally created as a memory-resident stream. 1N/A** When this memory is exceeded, a real temp file will be created. 1N/A** The temp file creation sequence is somewhat convoluted so that 1N/A** Written by David Korn and Kiem-Phong Vo. 1N/A/* File not removable while there is an open file descriptor. 1N/A** To ensure that temp files are properly removed, we need: 1N/A** 1. A discipline to remove a file when the corresponding stream is closed. 1N/A** Care must be taken to close the file descriptor before removing the 1N/A** file because systems such as NT do not allow file removal while 1N/A** there is an open file handle. 1N/A** 2. An atexit() function is set up to close temp files when process exits. 1N/A** 3. On systems with O_TEMPORARY (e.g., NT), this is used to further ensure 1N/A** that temp files will be removed after the last handle is closed. 1N/A#
endif /*_tmp_rmfail*/ 1N/A#
else /* can remove now */ 1N/A for(p =
path, n = 0;;)
/* count number of directories */ 1N/A while(*p && *p !=
':')
/* skip dir name */ 1N/A while(*p && *p !=
':')
1N/A#
endif /*!_PACKAGE_ast*/ 1N/A /* set up path of dirs to create temp files */ 1N/A /* set current directory to create this temp file */ 1N/A for(t = 0; t <
10; ++t)
1N/A {
/* compute a random name */ 1N/A if(A == 0 || t > 0)
/* get a quasi-random coefficient */ 1N/A Key = (A >>
16) | ((A&
0xffff)<<
16);
1N/A if((r = (A-
1) & 0
3) != 0)
/* Knuth vol.2, page.16, Thm.A */ 1N/A {
/* file already exists */ 1N/A {
/* reopen for read and write */ 1N/A /* don't know what happened but must remove file */ 1N/A#
endif /* _has_oflags */ 1N/A#
endif /* _PACKAGE_ast */ 1N/A /* the discipline needs to change only under the following exceptions */ 1N/A /* notify function */ 1N/A /* try to create the temp file */ 1N/A /* make sure that the notify function won't be called here since 1N/A we are only interested in creating the file, not the stream */ 1N/A /* make sure that new stream has the same mode */ 1N/A /* now remake the old stream into the new image */ 1N/A /* announce change of status */ 1N/A /* erase all traces of newf */ 1N/A /* start with a memory resident stream */ 1N/A /* make the file now */