On Thu, Jan 03, 2002 at 10:34:32PM +0200, Jarno Huuskonen wrote: > Hi, > > First of all why do you need to write your own copy of mkstemp ? > (see http://lwn.net/2000/1221/a/sec-tmp.php3) I need a way to create a tempfile for a process which run with a given uid, in a given directory owned from that uid, but i planned to use threads inside that process. The threads will work as a pipeline, and each thread can process huge logfiles for some pattern matching. And I wanna be sure to have no race conditions. > > while (count < 9) > > is 9 always less than MAX_BUFF ? Possibility for overflow. Yes. There are no possibilities for overflow as MAX_BUFF is defined as 11. > > > { > > fread (&num, sizeof (unsigned int), 1, urand_file); > > Why don't you check for read errors ? If the reads from urand_file fail > then the filename is not going to be very random. Right. This is my mistake. On read error I'll return NULL and free all dynamically allocated objects. The correct > > stream[count] = (char) num; > > count++; > > } > > base64_encode (&b, stream, 9); > > > > memset (filename, '\0', sizeof (filename)-1); > > mypid = (int) getpid(); > > snprintf (filename, sizeof (filename), "%s-%d-%s", appname, mypid, b.data); > > } > [cut] > > > if ((tmp = fdopen (fd, "r+b")) == NULL) > Are you going to write to to temp file (you open the file as readonly) ? as fdopen man page states: r+. Open for reading and writing. The stream is positionated at the beginning of the file. Thank your very much again for your feedbacks. -- ---------------------------- Giorgio Zoppi gzoppiat_private denebat_private
This archive was generated by hypermail 2b30 : Thu Jan 03 2002 - 15:50:21 PST