diff options
author | wens <wens@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2008-06-19 10:38:21 +0800 |
---|---|---|
committer | wens <wens@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2008-06-19 10:38:21 +0800 |
commit | 61a95bca5bfeb8426bcb6616d10f5eacfc9de612 (patch) | |
tree | 3b4082529f14af89a8acde1c03c24036eff5739d /common/bbs | |
parent | 8cb29110950daa71ef6247ed5d0ba1ea9320fa20 (diff) | |
download | pttbbs-61a95bca5bfeb8426bcb6616d10f5eacfc9de612.tar pttbbs-61a95bca5bfeb8426bcb6616d10f5eacfc9de612.tar.gz pttbbs-61a95bca5bfeb8426bcb6616d10f5eacfc9de612.tar.bz2 pttbbs-61a95bca5bfeb8426bcb6616d10f5eacfc9de612.tar.lz pttbbs-61a95bca5bfeb8426bcb6616d10f5eacfc9de612.tar.xz pttbbs-61a95bca5bfeb8426bcb6616d10f5eacfc9de612.tar.zst pttbbs-61a95bca5bfeb8426bcb6616d10f5eacfc9de612.zip |
Move stamp* to common library, with weak symbols
Remove stamplink
Header file cleanup
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4379 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'common/bbs')
-rw-r--r-- | common/bbs/Makefile | 2 | ||||
-rw-r--r-- | common/bbs/fhdr_stamp.c | 97 |
2 files changed, 98 insertions, 1 deletions
diff --git a/common/bbs/Makefile b/common/bbs/Makefile index 4b992b6a..458a01e6 100644 --- a/common/bbs/Makefile +++ b/common/bbs/Makefile @@ -5,7 +5,7 @@ MKPIC:=no SRCROOT:= ../.. .include "$(SRCROOT)/pttbbs.mk" -SRCS:= log.c file.c money.c names.c path.c time.c string.c # record.c +SRCS:= log.c file.c money.c names.c path.c time.c string.c fhdr_stamp.c LIB:= cmbbs install: diff --git a/common/bbs/fhdr_stamp.c b/common/bbs/fhdr_stamp.c new file mode 100644 index 00000000..97833316 --- /dev/null +++ b/common/bbs/fhdr_stamp.c @@ -0,0 +1,97 @@ +/* $Id$ */ +#include <stdio.h> +#include <errno.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/stat.h> +#include "cmsys.h" // for time4_t +#include "cmbbs.h" + +#if __GNUC__ +#define GCC_WEAK __attribute__ ((weak)) +#define GCC_INLINE __attribute__ ((always_inline)) +#else +#define GCC_WEAK +#define GCC_INLINE +#endif + +static inline int fhdr_stamp(char *fpath, fileheader_t *fh, int type) GCC_INLINE; +int stampfile(char *fpath, fileheader_t *fh) GCC_WEAK; +int stampdir(char *fpath, fileheader_t *fh) GCC_WEAK; +//int stamplink(char *fpath, fileheader_t * fh) GCC_WEAK; + +#define STAMP_FILE 0 +#define STAMP_DIR 1 +//#define STAMP_LINK 2 + +static inline int +fhdr_stamp(char *fpath, fileheader_t *fh, int type) +{ + char *ip = fpath; + time4_t dtime = time4(0); + struct tm ptime; + int res = 0; + + if (access(fpath, X_OK | R_OK | W_OK)) + mkdir(fpath, 0755); + + while (*(++ip)); + *ip++ = '/'; + + switch (type) { + case STAMP_FILE: + do { + sprintf(ip, "M.%d.A.%3.3X", (int)(++dtime), (unsigned int)(random() & 0xFFF)); + } while ((res = open(fpath, O_CREAT | O_EXCL | O_WRONLY, 0644)) == -1 && errno == EEXIST); + break; + case STAMP_DIR: + do { + sprintf(ip, "D%X", (int)++dtime & 07777); + } while ((res = mkdir(fpath, 0755)) == -1 && errno == EEXIST); + break; +#if 0 + case STAMP_LINK: + do { + sprintf(ip, "S%X", (int)++dtime); + } while ((res = symlink("temp", fpath)) == -1 && errno == EEXIST); + break; +#endif + default: + // unknown + return -1; + break; + } + + if (res == -1) + return -1; + close(res); + + memset(fh, 0, sizeof(fileheader_t)); + strlcpy(fh->filename, ip, sizeof(fh->filename)); + localtime4_r(&dtime, &ptime); + snprintf(fh->date, sizeof(fh->date), "%2d/%02d", ptime.tm_mon + 1, ptime.tm_mday); + + return 0; +} + +int +stampfile(char *fpath, fileheader_t *fh) +{ + return fhdr_stamp(fpath, fh, STAMP_FILE); +} + +int +stampdir(char *fpath, fileheader_t *fh) +{ + return fhdr_stamp(fpath, fh, STAMP_DIR); +} + +#if 0 +int +stamplink(char *fpath, fileheader_t * fh) +{ + return fhdr_stamp(fpath, fh, STAMP_LINK); +} +#endif + |