From b1608f31a0d106c73f7538c6e4e0c8f9038a0cbf Mon Sep 17 00:00:00 2001 From: scw Date: Mon, 12 Apr 2004 02:37:05 +0000 Subject: Avoid getting the same file name from stampfile() in utils. git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1740 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/record.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'mbbsd') diff --git a/mbbsd/record.c b/mbbsd/record.c index 276e0b13..21f1b99d 100644 --- a/mbbsd/record.c +++ b/mbbsd/record.c @@ -476,19 +476,26 @@ stampfile(char *fpath, fileheader_t * fh) register char *ip = fpath; time_t dtime = COMMON_TIME; struct tm *ptime; -// int fp = 0; //Ptt: don't need to check +#ifdef _BBS_UTIL_C_ + int fp = 0; //Ptt: don't need to check + // for utils, the time may be the same between several runs, by scw +#endif if (access(fpath, X_OK | R_OK | W_OK)) mkdir(fpath, 0755); while (*(++ip)); *ip++ = '/'; -// do { +#ifdef _BBS_UTIL_C_ + do { +#endif sprintf(ip, "M.%d.A.%3.3X", (int)++dtime, rand() & 0xFFF); -// if (fp == -1 && errno != EEXIST) -// return -1; -// } while ((fp = open(fpath, O_CREAT | O_EXCL | O_WRONLY, 0644)) == -1); -// close(fp); +#ifdef _BBS_UTIL_C_ + if (fp == -1 && errno != EEXIST) + return -1; + } while ((fp = open(fpath, O_CREAT | O_EXCL | O_WRONLY, 0644)) == -1); + close(fp); +#endif memset(fh, 0, sizeof(fileheader_t)); strlcpy(fh->filename, ip, sizeof(fh->filename)); ptime = localtime(&dtime); -- cgit v1.2.3