diff options
author | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2010-10-29 20:16:44 +0800 |
---|---|---|
committer | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2010-10-29 20:16:44 +0800 |
commit | 678ae3ad6b74fe5c7a20f15ca5e38cd3dfbf7c1e (patch) | |
tree | b72ffc0c81708d07af8bf9201cd10bea930e3aae | |
parent | 83096a0eb381652a5a36c054d01ec693eab906d9 (diff) | |
download | pttbbs-678ae3ad6b74fe5c7a20f15ca5e38cd3dfbf7c1e.tar pttbbs-678ae3ad6b74fe5c7a20f15ca5e38cd3dfbf7c1e.tar.gz pttbbs-678ae3ad6b74fe5c7a20f15ca5e38cd3dfbf7c1e.tar.bz2 pttbbs-678ae3ad6b74fe5c7a20f15ca5e38cd3dfbf7c1e.tar.lz pttbbs-678ae3ad6b74fe5c7a20f15ca5e38cd3dfbf7c1e.tar.xz pttbbs-678ae3ad6b74fe5c7a20f15ca5e38cd3dfbf7c1e.tar.zst pttbbs-678ae3ad6b74fe5c7a20f15ca5e38cd3dfbf7c1e.zip |
replace magic numbers by constant and more simple API
git-svn-id: http://opensvn.csie.org/pttbbs/trunk@5177 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
34 files changed, 132 insertions, 95 deletions
diff --git a/pttbbs/common/bbs/fhdr_stamp.c b/pttbbs/common/bbs/fhdr_stamp.c index 5a4af1db..82c6a1ee 100644 --- a/pttbbs/common/bbs/fhdr_stamp.c +++ b/pttbbs/common/bbs/fhdr_stamp.c @@ -39,7 +39,7 @@ fhdr_stamp(char *fpath, fileheader_t *fh, int type) int res = 0; if (access(fpath, X_OK | R_OK | W_OK)) - mkdir(fpath, 0755); + Mkdir(fpath); while (*(++ip)); *ip++ = '/'; @@ -47,13 +47,15 @@ fhdr_stamp(char *fpath, fileheader_t *fh, int type) 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); + sprintf(ip, "M.%d.A.%3.3X", (int)(++dtime), + (unsigned int)(random() & 0xFFF)); + } while ((res = OpenCreate(fpath, O_EXCL | O_WRONLY)) == -1 && + errno == EEXIST); break; case STAMP_DIR: do { sprintf(ip, "D%X", (int)++dtime & 07777); - } while ((res = mkdir(fpath, 0755)) == -1 && errno == EEXIST); + } while ((res = Mkdir(fpath)) == -1 && errno == EEXIST); break; case STAMP_LINK: do { diff --git a/pttbbs/common/bbs/passwd.c b/pttbbs/common/bbs/passwd.c index 71d995d9..6b80fe22 100644 --- a/pttbbs/common/bbs/passwd.c +++ b/pttbbs/common/bbs/passwd.c @@ -237,7 +237,7 @@ logattempt(const char *uid, char type, time4_t now, const char *loghost) Cdate(&now), loghost); len = strlen(genbuf); // log to public (BBSHOME) - if ((fd = open(FN_BADLOGIN, O_WRONLY | O_CREAT | O_APPEND, 0644)) > 0) { + if ((fd = OpenCreate(FN_BADLOGIN, O_WRONLY | O_APPEND)) > 0) { write(fd, genbuf, len); close(fd); } @@ -247,7 +247,7 @@ logattempt(const char *uid, char type, time4_t now, const char *loghost) "[%s] %s\n", Cdate(&now), loghost); len = strlen(genbuf); sethomefile(fname, uid, FN_BADLOGIN); - if ((fd = open(fname, O_WRONLY | O_CREAT | O_APPEND, 0644)) > 0) { + if ((fd = OpenCreate(fname, O_WRONLY | O_APPEND)) > 0) { write(fd, genbuf, len); close(fd); } diff --git a/pttbbs/common/sys/daemon.c b/pttbbs/common/sys/daemon.c index 4d490cb4..99b5465b 100644 --- a/pttbbs/common/sys/daemon.c +++ b/pttbbs/common/sys/daemon.c @@ -42,7 +42,7 @@ daemonize(const char * pidfile, const char * logfile) exit(0); if (pidfile) { - if ((fd = creat(pidfile, 0644)) >= 0) { + if ((fd = creat(pidfile, DEFAULT_FILE_CREATE_PERM)) >= 0) { snprintf(buf, sizeof(buf), "%d", (int)getpid()); write(fd, buf, strlen(buf)); close(fd); @@ -51,7 +51,7 @@ daemonize(const char * pidfile, const char * logfile) } if (logfile) { - if ((fd = open(logfile, O_WRONLY | O_CREAT | O_APPEND, 0644)) < 0) { + if ((fd = OpenCreate(logfile, O_WRONLY | O_APPEND)) < 0) { perror("Can't open logfile"); exit(1); } diff --git a/pttbbs/common/sys/file.c b/pttbbs/common/sys/file.c index e42b8c62..3d8d0b12 100644 --- a/pttbbs/common/sys/file.c +++ b/pttbbs/common/sys/file.c @@ -112,7 +112,7 @@ int copy_file_to_file(const char *src, const char *dst) if ((fdr = open(src, O_RDONLY)) < 0) return -1; - if ((fdw = open(dst, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) { + if ((fdw = OpenCreate(dst, O_WRONLY | O_TRUNC)) < 0) { close(fdr); return -1; } @@ -151,7 +151,7 @@ int copy_dir_to_dir(const char *src, const char *dst) char buf[PATH_MAX], buf2[PATH_MAX]; if (stat(dst, &st) < 0) - if (mkdir(dst, 0755) < 0) + if (Mkdir(dst) < 0) return -1; if ((dir = opendir(src)) == NULL) @@ -166,7 +166,7 @@ int copy_dir_to_dir(const char *src, const char *dst) if (stat(buf, &st) < 0) continue; if (S_ISDIR(st.st_mode)) - mkdir(buf2, 0755); + Mkdir(buf2); copy_file(buf, buf2); } @@ -236,7 +236,7 @@ Copy(const char *src, const char *dst) char buf[8192]; fi=open(src, O_RDONLY); if(fi<0) return -1; - fo=open(dst, O_WRONLY | O_TRUNC | O_CREAT, 0644); + fo=OpenCreate(dst, O_WRONLY | O_TRUNC); if(fo<0) {close(fi); return -1;} while((bytes=read(fi, buf, sizeof(buf)))>0) write(fo, buf, bytes); @@ -254,7 +254,7 @@ CopyN(const char *src, const char *dst, int n) fi=open(src, O_RDONLY); if(fi<0) return -1; - fo=open(dst, O_WRONLY | O_TRUNC | O_CREAT, 0644); + fo=OpenCreate(dst, O_WRONLY | O_TRUNC); if(fo<0) {close(fi); return -1;} while(n > 0 && (bytes=read(fi, buf, sizeof(buf)))>0) @@ -279,7 +279,7 @@ AppendTail(const char *src, const char *dst, int off) fi=open(src, O_RDONLY); if(fi<0) return -1; - fo=open(dst, O_WRONLY | O_APPEND | O_CREAT, 0644); + fo=OpenCreate(dst, O_WRONLY | O_APPEND); if(fo<0) {close(fi); return -1;} // flock(dst, LOCK_SH); @@ -324,6 +324,27 @@ HardLink(const char *src, const char *dst) return Copy(src, dst); } +/** + * @param path directory name + * @return 0 if success + */ +int +Mkdir(const char *path) +{ + return mkdir(path, DEFAULT_FOLDER_CREATE_PERM); +} + +/** + * @param path directory name + * @param flags optional parameters + * @return 0 if success + */ +int +OpenCreate(const char *path, int flags) +{ + return open(path, flags | O_CREAT, DEFAULT_FILE_CREATE_PERM); +} + /* ----------------------------------------------------- */ /* 檔案內容處理函數:以「行」為單位 */ /* ----------------------------------------------------- */ diff --git a/pttbbs/common/sys/log.c b/pttbbs/common/sys/log.c index 7fa94d77..1db30c1c 100644 --- a/pttbbs/common/sys/log.c +++ b/pttbbs/common/sys/log.c @@ -24,7 +24,7 @@ log_file(const char *fn, int log_flag, const char *msg) { int fd; int flag = O_APPEND | O_WRONLY; - int mode = 0644; + int mode = DEFAULT_FILE_CREATE_PERM; if (log_flag & LOG_CREAT) flag |= O_CREAT; diff --git a/pttbbs/common/sys/record.c b/pttbbs/common/sys/record.c index 340ccccc..ee417dac 100644 --- a/pttbbs/common/sys/record.c +++ b/pttbbs/common/sys/record.c @@ -75,7 +75,7 @@ substitute_record(const char *fpath, const void *rptr, size_t size, int id) int fd; off_t offset = size * (id - 1); - if (id < 1 || (fd = open(fpath, O_WRONLY | O_CREAT, 0644)) == -1) + if (id < 1 || (fd = OpenCreate(fpath, O_WRONLY)) == -1) return -1; lseek(fd, offset, SEEK_SET); @@ -92,7 +92,7 @@ append_record(const char *fpath, const void *record, size_t size) { int fd, index = -2, fsize = 0; - if ((fd = open(fpath, O_WRONLY | O_CREAT, 0644)) == -1) + if ((fd = OpenCreate(fpath, O_WRONLY)) == -1) return -1; flock(fd, LOCK_EX); diff --git a/pttbbs/include/cmsys.h b/pttbbs/include/cmsys.h index 3a8a9dd9..78fb641d 100644 --- a/pttbbs/include/cmsys.h +++ b/pttbbs/include/cmsys.h @@ -64,6 +64,8 @@ extern int CopyN(const char *src, const char *dst, int n); extern int AppendTail(const char *src, const char *dst, int off); extern int Link(const char *src, const char *dst); extern int HardLink(const char *src, const char *dst); +extern int Mkdir(const char *path); +extern int OpenCreate(const char *path, int flags); extern int file_count_line(const char *file); extern int file_append_line(const char *file, const char *string); // does not append "\n" extern int file_append_record(const char *file, const char *key); // will append "\n" diff --git a/pttbbs/include/config.h b/pttbbs/include/config.h index 00b3e346..401a8d11 100644 --- a/pttbbs/include/config.h +++ b/pttbbs/include/config.h @@ -344,4 +344,11 @@ #define FROMHOST fromhost #endif +#ifndef DEFAULT_FOLDER_CREATE_PERM +#define DEFAULT_FOLDER_CREATE_PERM (0755) +#endif +#ifndef DEFAULT_FILE_CREATE_PERM +#define DEFAULT_FILE_CREATE_PERM (0644) +#endif + #endif diff --git a/pttbbs/mbbsd/acl.c b/pttbbs/mbbsd/acl.c index 35197cb5..bb94a9fb 100644 --- a/pttbbs/mbbsd/acl.c +++ b/pttbbs/mbbsd/acl.c @@ -23,7 +23,7 @@ bakuman_make_tag_filename(const char *who, const char *object, char object_type, else sethomefile(buf, who, FN_BANNED "/"); if (create_folder && !dashd(buf)) { - mkdir(buf, 0755); + Mkdir(buf); } strlcat(buf, prefix, szbuf); strlcat(buf, object, szbuf); diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index f3511a17..f5c002b0 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -360,7 +360,7 @@ AddingChessCountryFiles(const char* apath) /* creating chess country regalia */ snprintf(filename, sizeof(filename), "%s/chess_ensign", apath); - close(open(filename, O_CREAT | O_WRONLY, 0644)); + close(OpenCreate(filename, O_WRONLY)); strlcpy(symbolicname, apath, sizeof(symbolicname)); stampfile(symbolicname, &fh); @@ -392,7 +392,7 @@ AddingChessCountryFiles(const char* apath) /* creating profession photos' dir */ snprintf(filename, sizeof(filename), "%s/chess_photo", apath); - mkdir(filename, 0755); + Mkdir(filename); strlcpy(symbolicname, apath, sizeof(symbolicname)); stampfile(symbolicname, &fh); @@ -411,7 +411,7 @@ setup_man(const boardheader_t * board, const boardheader_t * oldboard) char genbuf[200]; setapath(genbuf, board->brdname); - mkdir(genbuf, 0755); + Mkdir(genbuf); #ifdef CHESSCOUNTRY if (oldboard == NULL || oldboard->chesscountry != board->chesscountry) @@ -814,7 +814,7 @@ m_newbrd(int whatclass, int recover) setbpath(genbuf, newboard.brdname); if (!recover && - (getbnum(newboard.brdname) > 0 || mkdir(genbuf, 0755) == -1)) { + (getbnum(newboard.brdname) > 0 || Mkdir(genbuf) == -1)) { vmsg("此看板已經存在! 請取不同英文板名"); return -1; } diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index c95145d9..654afa1d 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -532,7 +532,7 @@ a_pasteitem(menu_t * pm, int mode) else return; if (access(pm->path, X_OK | R_OK | W_OK)) - mkdir(pm->path, 0755); + Mkdir(pm->path); memset(&item, 0, sizeof(fileheader_t)); strlcpy(item.filename, fname + 1, sizeof(item.filename)); memcpy(cq->copytitle, "◎", 2); diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 5a328667..2bb60392 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -148,10 +148,10 @@ add_to_post_history( setdirpath(hist_file, direct, FN_EDITHISTORY "/"); if (!dashd(hist_file)) - mkdir(hist_file, 0755); + Mkdir(hist_file); strlcat(hist_file, basename, sizeof(hist_file)); - if ((fd = open(hist_file, O_RDWR|O_CREAT, 0644)) >= 0) { + if ((fd = OpenCreate(hist_file, O_RDWR)) >= 0) { // XXX if somebody just die inside... locks everyone! flock(fd, LOCK_EX); read(fd, &last_index, sizeof(last_index)); @@ -2344,7 +2344,7 @@ b_man(void) char genbuf[128]; int fd; snprintf(genbuf, sizeof(genbuf), "%s/.rebuild", buf); - if ((fd = open(genbuf, O_CREAT, 0644)) > 0) + if ((fd = OpenCreate(genbuf, O_RDWR)) > 0) close(fd); } return a_menu(currboard, buf, HasUserPerm(PERM_ALLBOARD) ? 2 : diff --git a/pttbbs/mbbsd/bbslua.c b/pttbbs/mbbsd/bbslua.c index 414096b0..b62cb657 100644 --- a/pttbbs/mbbsd/bbslua.c +++ b/pttbbs/mbbsd/bbslua.c @@ -748,7 +748,10 @@ bls_setfn(char *fn, size_t sz, const char *p) case BLS_USER: setuserfile(fn, BLSCONF_UPATH); - mkdir(fn, 0755); +#ifndef DEFAULT_FOLDER_CREATE_PERM +#define DEFAULT_FOLDER_CREATE_PERM (0755) +#endif + mkdir(fn, DEFAULT_FOLDER_CREATE_PERM); assert(strlen(fn) +8 <= sz); snprintf(fn + strlen(fn), sz - strlen(fn), @@ -858,7 +861,7 @@ bls_save(lua_State *L) // write file! if (bls_setfn(fn, sizeof(fn), cat)) { - fd = open(fn, O_WRONLY|O_CREAT, 0644); + fd = OpenCreate(fn, O_WRONLY); if (fd >= 0) { write(fd, s, slen); diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index ccf51f22..df709f6d 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -109,7 +109,7 @@ int enter_board(const char *boardname) return -3; setbpath(bpath, bname); - // mkdir(bpath, 755); + // Mkdir(bpath); if (stat(bpath, &st) == -1) { return -3; } @@ -2121,7 +2121,7 @@ choose_board(int newflag) if (IN_SUBCLASS() && (HasUserPerm(PERM_SYSOP) || GROUPOP())) { setbpath(buf, getbcache(class_bid)->brdname); - mkdir(buf, 0755); /* Ptt:開群組目錄 */ + Mkdir(buf); /* Ptt:開群組目錄 */ b_note_edit_bname(class_bid); brdnum = -1; } diff --git a/pttbbs/mbbsd/brc.c b/pttbbs/mbbsd/brc.c index 56a6707b..7de71072 100644 --- a/pttbbs/mbbsd/brc.c +++ b/pttbbs/mbbsd/brc.c @@ -380,7 +380,7 @@ brc_finalize(){ setuserfile(brcfile, fn_brc); snprintf(tmpfile, sizeof(tmpfile), "%s.tmp.%x", brcfile, getpid()); if (brc_buf != NULL) { - int fd = open(tmpfile, O_WRONLY | O_CREAT | O_TRUNC, 0644); + int fd = OpenCreate(tmpfile, O_WRONLY | O_TRUNC); if (fd != -1) { int ok=0; if(write(fd, brc_buf, brc_size)==brc_size) diff --git a/pttbbs/mbbsd/chicken.c b/pttbbs/mbbsd/chicken.c index 590f523a..99aba620 100644 --- a/pttbbs/mbbsd/chicken.c +++ b/pttbbs/mbbsd/chicken.c @@ -231,7 +231,7 @@ new_chicken(void) // flush it setuserfile(fn, FN_CHICKEN); - fd = open(fn, O_WRONLY|O_CREAT, 0644); + fd = OpenCreate(fn, O_WRONLY); if (fd < 0) { vmsg("系統錯誤: 無法建立資料,請至 " BN_BUGREPORT " 報告。"); diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index 3a38ddb8..8a42528e 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1580,7 +1580,7 @@ read_file(const char *fpath, int splitSig) if ((fp = fopen(fpath, "r")) == NULL) { int fd; - if ((fd = creat(fpath, 0644)) >= 0) { + if ((fd = creat(fpath, DEFAULT_FILE_CREATE_PERM)) >= 0) { close(fd); return 0; } diff --git a/pttbbs/mbbsd/fav.c b/pttbbs/mbbsd/fav.c index 2c673b7d..ffe9eeb1 100644 --- a/pttbbs/mbbsd/fav.c +++ b/pttbbs/mbbsd/fav.c @@ -1141,7 +1141,7 @@ int updatenewfav(int mode) setuserfile(fname, FAVNB); - if( (fd = open(fname, O_RDWR | O_CREAT, 0644)) != -1 ){ + if( (fd = OpenCreate(fname, O_RDWR)) != -1 ){ assert(numboards>=0); brdnum = numboards; /* avoid race */ diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 3f62a8f8..564caad3 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -79,7 +79,7 @@ void UpdateClientCode(unsigned char c) void LogClientCode() { - int fd = open("log/client_code",O_WRONLY | O_CREAT | O_APPEND, 0644); + int fd = OpenCreate("log/client_code",O_WRONLY | O_APPEND); if(fd>=0) { write(fd, &client_code, sizeof(client_code)); close(fd); @@ -134,7 +134,7 @@ start_daemon(struct ProgramOption *option) while (n) close(--n); - if( ((fd = open("log/stderr", O_WRONLY | O_CREAT | O_APPEND, 0644)) >= 0) && fd != 2 ){ + if( ((fd = OpenCreate("log/stderr", O_WRONLY | O_APPEND)) >= 0) && fd != 2 ){ dup2(fd, 2); close(fd); } @@ -683,7 +683,7 @@ mkuserdir(const char *userid) sethomepath(genbuf, userid); // assume it is a dir, so just check if it is exist if (access(genbuf, F_OK) != 0) - mkdir(genbuf, 0755); + Mkdir(genbuf); } static int @@ -1862,7 +1862,8 @@ shell_login(char *argv0, struct ProgramOption *option) snprintf(margs, sizeof(margs), "%s ssh ", argv0); close(2); /* don't close fd 1, at least init_tty need it */ - if( ((fd = open("log/stderr", O_WRONLY | O_CREAT | O_APPEND, 0644)) >= 0) && fd != 2 ){ + if(((fd = OpenCreate("log/stderr", O_WRONLY | O_APPEND)) >= 0) && + fd != 2 ){ dup2(fd, 2); close(fd); } diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index 857e869d..97312ae7 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -698,7 +698,8 @@ select_read(const keeploc_t * locmem, int sr_mode) reference = 0; } - if( (fd = open(newdirect, filemode, 0644)) == -1 ) { + if((fd = open(newdirect, filemode, DEFAULT_FILE_CREATE_PERM)) == -1) + { close(fr); return READ_REDRAW; } diff --git a/pttbbs/mbbsd/record.c b/pttbbs/mbbsd/record.c index 8ac2ab3f..255f95f9 100644 --- a/pttbbs/mbbsd/record.c +++ b/pttbbs/mbbsd/record.c @@ -128,7 +128,7 @@ force_open(const char *fname) if (dasht(fname) > expire) return -1; unlink(fname); - fd = open(fname, O_WRONLY | O_TRUNC, 0644); + fd = OpenCreate(fname, O_WRONLY | O_TRUNC); return fd; } @@ -185,18 +185,18 @@ delete_range(const char *fpath, int id1, int id2) nolfilename(&my, fpath); - if ((fd = open(my.lockfn, O_RDWR | O_CREAT | O_APPEND, 0644)) == -1) + if ((fd = OpenCreate(my.lockfn, O_RDWR | O_APPEND)) == -1) return -1; flock(fd, LOCK_EX); - if ((fdr = open(fpath, O_RDONLY, 0)) == -1) { + if ((fdr = open(fpath, O_RDONLY)) == -1) { flock(fd, LOCK_UN); close(fd); return -1; } if ( - ((fdw = open(my.newfn, O_WRONLY | O_CREAT | O_EXCL, 0644)) == -1) && + ((fdw = OpenCreate(my.newfn, O_WRONLY | O_EXCL)) == -1) && ((fdw = force_open(my.newfn)) == -1)) { close(fdr); flock(fd, LOCK_UN); @@ -347,7 +347,7 @@ stampadir(char *fpath, fileheader_t * fh, int large_set) // try to create root path if (access(fpath, X_OK | R_OK | W_OK) != 0) - mkdir(fpath, 0755); + Mkdir(fpath); // find tail while (*(++ip)); @@ -368,7 +368,7 @@ stampadir(char *fpath, fileheader_t * fh, int large_set) // create minimal length file name. sprintf(ip, "D%X", (int)++dtime & mask); - } while (mkdir(fpath, 0755) == -1); + } while (Mkdir(fpath) == -1); strlcpy(fh->filename, ip, sizeof(fh->filename)); localtime4_r(&dtime, &ptime); diff --git a/pttbbs/mbbsd/register.c b/pttbbs/mbbsd/register.c index 315b34db..bf666d39 100644 --- a/pttbbs/mbbsd/register.c +++ b/pttbbs/mbbsd/register.c @@ -302,7 +302,7 @@ makeregcode(char *buf) buf[i] = alphabet[random() % strlen(alphabet)]; getregfile(fpath); - if( (fd = open(fpath, O_WRONLY | O_CREAT, 0644)) == -1 ){ + if((fd = OpenCreate(fpath, O_WRONLY)) == -1){ perror("open"); exit(1); } @@ -565,7 +565,7 @@ setupnewuser(const userec_t *user) if ((uid = dosearchuser("", NULL)) == 0) { /* 每 1 個小時,清理 user 帳號一次 */ if ((stat(fn_fresh, &st) == -1) || (st.st_mtime < clock - 3600)) { - if ((fd = open(fn_fresh, O_RDWR | O_CREAT, 0644)) == -1) + if ((fd = OpenCreate(fn_fresh, O_RDWR)) == -1) return -1; write(fd, ctime(&clock), 25); close(fd); @@ -573,7 +573,7 @@ setupnewuser(const userec_t *user) fprintf(stdout, "尋找新帳號中, 請稍待片刻...\n\r"); - if ((fd = open(fn_passwd, O_RDWR | O_CREAT, 0644)) == -1) + if ((fd = OpenCreate(fn_passwd, O_RDWR)) == -1) return -1; /* 不曉得為什麼要從 2 開始... Ptt:因為SYSOP在1 */ diff --git a/pttbbs/mbbsd/vote.c b/pttbbs/mbbsd/vote.c index e604e454..d53cb4ca 100644 --- a/pttbbs/mbbsd/vote.c +++ b/pttbbs/mbbsd/vote.c @@ -146,7 +146,7 @@ vote_report(const char *bname, const char *fname, char *fpath) for (;;) { /* TODO: extract record.c:stampfile_u() to common lib */ sprintf(ip, "M.%d.A.%3.3X", (int)++dtime, (unsigned int)(random() & 0xFFF)); - fd = open(fpath, O_CREAT | O_EXCL | O_WRONLY, 0644); + fd = OpenCreate(fpath, O_EXCL | O_WRONLY); if (fd >= 0) break; dtime++; @@ -172,7 +172,7 @@ vote_report(const char *bname, const char *fname, char *fpath) strlcpy(header.filename, ip, sizeof(header.filename)); strcpy(ip, FN_DIR); - if ((fd = open(fpath, O_WRONLY | O_CREAT, 0644)) >= 0) { + if ((fd = OpenCreate(fpath, O_WRONLY)) >= 0) { flock(fd, LOCK_EX); lseek(fd, 0, SEEK_END); write(fd, &header, sizeof(fileheader_t)); @@ -732,7 +732,7 @@ vote_flag(const vote_buffer_t *vbuf, const char *bname, char val) num = usernum - 1; setbfile(buf, bname, vbuf->flags); - if ((fd = open(buf, O_RDWR | O_CREAT, 0644)) == -1) + if ((fd = OpenCreate(buf, O_RDWR)) == -1) return -1; size = lseek(fd, 0, SEEK_END); memset(buf, 0, sizeof(buf)); @@ -913,7 +913,7 @@ user_vote_one(const vote_buffer_t *vbuf, const char *bname) outs("重複投票! 不予計票。"); else { setbfile(buf, bname, vbuf->ballots); - if ((fd = open(buf, O_WRONLY | O_CREAT | O_APPEND, 0644)) == 0) + if ((fd = OpenCreate(buf, O_WRONLY | O_APPEND)) == 0) outs("無法投入票匭\n"); else { struct stat statb; diff --git a/pttbbs/util/account.c b/pttbbs/util/account.c index e7164293..201709d0 100644 --- a/pttbbs/util/account.c +++ b/pttbbs/util/account.c @@ -454,7 +454,7 @@ main(int argc, char **argv) const char const fn2[] = "suicide"; rename(fn1, fn2); - mkdir(fn1, 0755); + Mkdir(fn1); sprintf(buf, "tar cfz adm/%s-%02d%02d%02d.tgz %s", fn2, tm_now.tm_year % 100, tm_now.tm_mon + 1, tm_now.tm_mday, fn2); system(buf); diff --git a/pttbbs/util/angel.c b/pttbbs/util/angel.c index a3121c9a..780af2f0 100644 --- a/pttbbs/util/angel.c +++ b/pttbbs/util/angel.c @@ -86,7 +86,7 @@ void sendResult(){ sprintf(filename, BBSHOME "/home/%c/%s", mailto[0], mailto); if (stat(filename, &st) == -1) { - if (mkdir(filename, 0755) == -1) { + if (Mkdir(filename) == -1) { fprintf(stderr, "mail box create error %s \n", filename); return; } diff --git a/pttbbs/util/bbsmail.c b/pttbbs/util/bbsmail.c index 9bfcbd7d..b141b74e 100644 --- a/pttbbs/util/bbsmail.c +++ b/pttbbs/util/bbsmail.c @@ -95,7 +95,7 @@ int mail2bbs(char *userid) sprintf(filename, BBSHOME "/home/%c/%s", xuser.userid[0], xuser.userid); if( stat(filename, &st) == -1 ){ - if( mkdir(filename, 0755) == -1 ){ + if( Mkdir(filename) == -1 ){ printf("mail box create error %s \n", filename); return -1; } diff --git a/pttbbs/util/buildAnnounce.c b/pttbbs/util/buildAnnounce.c index d1333c4a..8bc526bd 100644 --- a/pttbbs/util/buildAnnounce.c +++ b/pttbbs/util/buildAnnounce.c @@ -49,7 +49,7 @@ void buildchilds(int level,char *path,int gid) if(ptr->brdattr & BRD_GROUPBOARD){ snprintf(newpath,sizeof(newpath),"%s/%s",path,ptr->brdname); - mkdir(newpath,0755); + Mkdir(newpath); buildchilds(level+1,newpath,ptr-bcache+1); } else{ @@ -81,7 +81,7 @@ int main(int argc, char **argv) setsid(); strcpy(path,GROUPROOT); system("rm -rf "GROUPROOT); - mkdir(GROUPROOT,0755); + Mkdir(GROUPROOT); attach_SHM(); resolve_boards(); buildchilds(0,path,1); diff --git a/pttbbs/util/buildir.c b/pttbbs/util/buildir.c index cc30c437..adbfbb1a 100644 --- a/pttbbs/util/buildir.c +++ b/pttbbs/util/buildir.c @@ -26,7 +26,7 @@ int main(int argc, char **argv) struct dirent **dirlist; sprintf(path, "%s/.DIR", argv[k]); - if((fdir = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644)) == -1) { + if((fdir = OpenCreate(path, O_WRONLY | O_TRUNC)) == -1) { perror(path); continue; } diff --git a/pttbbs/util/cleanpasswd.c b/pttbbs/util/cleanpasswd.c index e2769d12..1bdfd944 100644 --- a/pttbbs/util/cleanpasswd.c +++ b/pttbbs/util/cleanpasswd.c @@ -27,7 +27,7 @@ int main(int argc, char *argv[]) exit(-1); } - if ((fdw = open(BBSHOME"/.PASSWDS.new", O_WRONLY | O_TRUNC | O_CREAT, 0644)) < 0){ + if ((fdw = OpenCreate(BBSHOME"/.PASSWDS.new", O_WRONLY | O_TRUNC)) < 0){ perror("open .PASSWDS.new error"); exit(-1); } diff --git a/pttbbs/util/expire.c b/pttbbs/util/expire.c index 0b809464..bfcf1e31 100644 --- a/pttbbs/util/expire.c +++ b/pttbbs/util/expire.c @@ -94,7 +94,7 @@ void expire(life_t *brd) setbfile(index, brd->bname, ".DIR"); sprintf(lockfile, "%s.lock", index); - if ((fdlock = open(lockfile, O_RDWR | O_CREAT | O_APPEND, 0644)) == -1){ + if ((fdlock = OpenCreate(lockfile, O_RDWR | O_APPEND)) == -1){ perror("open lock file error"); return; } @@ -114,7 +114,7 @@ void expire(life_t *brd) } // TODO use fread/fwrite to reduce system calls if( checkmode || - (fdw = open(tmpfile, O_WRONLY | O_CREAT | O_EXCL, 0644)) > 0 ){ + (fdw = OpenCreate(tmpfile, O_WRONLY | O_EXCL)) > 0 ){ while( read(fdr, &head, sizeof(head)) == sizeof(head) ){ done = 1; ftime = atoi(head.filename + 2); diff --git a/pttbbs/util/initbbs.c b/pttbbs/util/initbbs.c index 9fbf14df..7042e2c5 100644 --- a/pttbbs/util/initbbs.c +++ b/pttbbs/util/initbbs.c @@ -2,28 +2,28 @@ #include "bbs.h" static void initDir() { - mkdir("adm", 0755); - mkdir("boards", 0755); - mkdir("etc", 0755); - mkdir("man", 0755); - mkdir("man/boards", 0755); - mkdir("out", 0755); - mkdir("tmp", 0755); - mkdir("run", 0755); - mkdir("jobspool", 0755); + Mkdir("adm"); + Mkdir("boards"); + Mkdir("etc"); + Mkdir("man"); + Mkdir("man/boards"); + Mkdir("out"); + Mkdir("tmp"); + Mkdir("run"); + Mkdir("jobspool"); } static void initHome() { int i; char buf[256]; - mkdir("home", 0755); + Mkdir("home"); strcpy(buf, "home/?"); for(i = 0; i < 26; i++) { buf[5] = 'A' + i; - mkdir(buf, 0755); + Mkdir(buf); buf[5] = 'a' + i; - mkdir(buf, 0755); + Mkdir(buf); #if 0 /* in current implementation we don't allow * id as digits so we don't create now. */ @@ -31,7 +31,7 @@ static void initHome() { continue; /* 0~9 */ buf[5] = '0' + i; - mkdir(buf, 0755); + Mkdir(buf); #endif } } @@ -40,18 +40,18 @@ static void initBoardsDIR() { int i; char buf[256]; - mkdir("boards", 0755); + Mkdir("boards"); strcpy(buf, "boards/?"); for(i = 0; i < 26; i++) { buf[7] = 'A' + i; - mkdir(buf, 0755); + Mkdir(buf); buf[7] = 'a' + i; - mkdir(buf, 0755); + Mkdir(buf); if(i >= 10) continue; /* 0~9 */ buf[7] = '0' + i; - mkdir(buf, 0755); + Mkdir(buf); } } @@ -59,19 +59,19 @@ static void initManDIR() { int i; char buf[256]; - mkdir("man", 0755); - mkdir("man/boards", 0755); + Mkdir("man"); + Mkdir("man/boards"); strcpy(buf, "man/boards/?"); for(i = 0; i < 26; i++) { buf[11] = 'A' + i; - mkdir(buf, 0755); + Mkdir(buf); buf[11] = 'a' + i; - mkdir(buf, 0755); + Mkdir(buf); if(i >= 10) continue; /* 0~9 */ buf[11] = '0' + i; - mkdir(buf, 0755); + Mkdir(buf); } } @@ -93,9 +93,9 @@ static void newboard(FILE *fp, boardheader_t *b) { fwrite(b, sizeof(boardheader_t), 1, fp); sprintf(buf, "boards/%c/%s", b->brdname[0], b->brdname); - mkdir(buf, 0755); + Mkdir(buf); sprintf(buf, "man/boards/%c/%s", b->brdname[0], b->brdname); - mkdir(buf, 0755); + Mkdir(buf); } static void initBoards() { @@ -228,27 +228,27 @@ static void initMan() { strcpy(f.filename, "SONGBOOK"); strcpy(f.title, "◆ 【點 歌 歌 本】"); fwrite(&f, sizeof(f), 1, fp); - mkdir("man/boards/N/Note/SONGBOOK", 0755); + Mkdir("man/boards/N/Note/SONGBOOK"); strcpy(f.filename, "SONGO"); strcpy(f.title, "◆ <點歌> 動態看板"); fwrite(&f, sizeof(f), 1, fp); - mkdir("man/boards/N/Note/SONGO", 0755); + Mkdir("man/boards/N/Note/SONGO"); strcpy(f.filename, "SYS"); strcpy(f.title, "◆ <系統> 動態看板"); fwrite(&f, sizeof(f), 1, fp); - mkdir("man/boards/N/Note/SYS", 0755); + Mkdir("man/boards/N/Note/SYS"); strcpy(f.filename, "AD"); strcpy(f.title, "◆ <廣告> 動態看板"); fwrite(&f, sizeof(f), 1, fp); - mkdir("man/boards/N/Note/AD", 0755); + Mkdir("man/boards/N/Note/AD"); strcpy(f.filename, "NEWS"); strcpy(f.title, "◆ <新聞> 動態看板"); fwrite(&f, sizeof(f), 1, fp); - mkdir("man/boards/N/Note/NEWS", 0755); + Mkdir("man/boards/N/Note/NEWS"); fclose(fp); } diff --git a/pttbbs/util/mailangel.c b/pttbbs/util/mailangel.c index 00906a4c..62434aa0 100644 --- a/pttbbs/util/mailangel.c +++ b/pttbbs/util/mailangel.c @@ -96,7 +96,7 @@ void mailUser(char *userid) sprintf(filename, BBSHOME "/home/%c/%s", userid[0], userid); if (stat(filename, &st) == -1) { - if (mkdir(filename, 0755) == -1) { + if (Mkdir(filename) == -1) { fprintf(stderr, "mail box create error %s \n", filename); return; } diff --git a/pttbbs/util/tunepasswd.c b/pttbbs/util/tunepasswd.c index 0cf03046..b1981be3 100644 --- a/pttbbs/util/tunepasswd.c +++ b/pttbbs/util/tunepasswd.c @@ -13,7 +13,7 @@ int tune(int num) { printf("Lock failed!\n"); return 1; } - if((fout = open(FN_PASSWD ".tune" , O_WRONLY | O_CREAT, 0644)) == -1) { + if((fout = OpenCreate(FN_PASSWD ".tune" , O_WRONLY)) == -1) { perror(FN_PASSWD ".tune"); flock(fin, LOCK_UN); close(fin); diff --git a/pttbbs/util/xchatd.c b/pttbbs/util/xchatd.c index 2e03d1ce..58522a0f 100644 --- a/pttbbs/util/xchatd.c +++ b/pttbbs/util/xchatd.c @@ -246,13 +246,13 @@ logit(char *key, char *msg) static void log_init() { - flog = open(CHAT_LOGFILE, O_WRONLY | O_CREAT | O_APPEND, 0644); + flog = OpenCreate(CHAT_LOGFILE, O_WRONLY | O_APPEND); logit("START", "chat daemon"); #ifdef CHAT_MSG_LOGFILE { const char *dtstr = Cdate(&boot_time); const char *prefix = "\n- xchatd restart: "; - mlog = open(CHAT_MSG_LOGFILE, O_WRONLY | O_CREAT | O_APPEND, 0644); + mlog = OpenCreate(CHAT_MSG_LOGFILE, O_WRONLY | O_APPEND); write(mlog, prefix, strlen(prefix)); write(mlog, dtstr, strlen(dtstr)); write(mlog, "\n", 1); @@ -2667,7 +2667,7 @@ start_daemon() #endif - fd = open(CHAT_PIDFILE, O_WRONLY | O_CREAT | O_TRUNC, 0644); + fd = OpenCreate(CHAT_PIDFILE, O_WRONLY | O_TRUNC); if (fd >= 0) { /* sprintf(buf, "%5d\n", value); */ |