--- deliantra/server/common/porting.C 2006/08/13 17:16:00 1.1 +++ deliantra/server/common/porting.C 2006/08/29 08:01:35 1.2 @@ -1,6 +1,6 @@ /* * static char *rcsid_porting_c = - * "$Id: porting.C,v 1.1 2006/08/13 17:16:00 elmex Exp $"; + * "$Id: porting.C,v 1.2 2006/08/29 08:01:35 root Exp $"; */ /* @@ -98,10 +98,10 @@ #endif if (!(name = (char *) malloc(MAXPATHLEN))) - return(NULL); + return(NULL); if (!pfx) - pfx = "cftmp."; + pfx = "cftmp."; /* This is a pretty simple method - put the pid as a hex digit and * just keep incrementing the last digit. Check to see if the file @@ -109,15 +109,15 @@ * find one that is free. */ if (dir!=NULL) { - do { + do { #ifdef HAVE_SNPRINTF - (void)snprintf(name, MAXPATHLEN, "%s/%s%hx.%d", dir, pfx, pid, curtmp); + (void)snprintf(name, MAXPATHLEN, "%s/%s%hx.%d", dir, pfx, pid, curtmp); #else - (void)sprintf(name,"%s/%s%hx%d", dir, pfx, pid, curtmp); + (void)sprintf(name,"%s/%s%hx%d", dir, pfx, pid, curtmp); #endif - curtmp++; - } while (access(name, F_OK)!=-1); - return(name); + curtmp++; + } while (access(name, F_OK)!=-1); + return(name); } return(NULL); } @@ -133,33 +133,33 @@ int status; if ((dirp=opendir(path))!=NULL) { - struct dirent *de; + struct dirent *de; - for (de=readdir(dirp); de; de = readdir(dirp)) { - /* Don't remove '.' or '..' In theory we should do a better - * check for .., but the directories we are removing are fairly - * limited and should not have dot files in them. - */ - if (de->d_name[0] == '.') continue; - - /* Linux actually has a type field in the dirent structure, - * but that is not portable - stat should be portable - */ - status=stat(de->d_name, &statbuf); - if ((status!=-1) && (S_ISDIR(statbuf.st_mode))) { - sprintf(buf,"%s/%s", path, de->d_name); - remove_directory(buf); - continue; - } - sprintf(buf,"%s/%s", path, de->d_name); - if (unlink(buf)) { - LOG(llevError,"Unable to remove directory %s\n", path); - } - } - closedir(dirp); + for (de=readdir(dirp); de; de = readdir(dirp)) { + /* Don't remove '.' or '..' In theory we should do a better + * check for .., but the directories we are removing are fairly + * limited and should not have dot files in them. + */ + if (de->d_name[0] == '.') continue; + + /* Linux actually has a type field in the dirent structure, + * but that is not portable - stat should be portable + */ + status=stat(de->d_name, &statbuf); + if ((status!=-1) && (S_ISDIR(statbuf.st_mode))) { + sprintf(buf,"%s/%s", path, de->d_name); + remove_directory(buf); + continue; + } + sprintf(buf,"%s/%s", path, de->d_name); + if (unlink(buf)) { + LOG(llevError,"Unable to remove directory %s\n", path); + } + } + closedir(dirp); } if (rmdir(path)) { - LOG(llevError,"Unable to remove directory %s\n", path); + LOG(llevError,"Unable to remove directory %s\n", path); } } @@ -173,53 +173,53 @@ FILE *popen_local(const char *command, const char *type) { - int fd[2]; - int pd; - FILE *ret; - if (!strcmp(type,"r")) - { - pd=STDOUT_FILENO; - } - else if (!strcmp(type,"w")) - { - pd=STDIN_FILENO; - } - else - { - return NULL; - } - if (pipe(fd)!=-1) - { - switch (fork()) - { - case -1: - close(fd[0]); - close(fd[1]); - break; - case 0: - close(fd[0]); - if ((fd[1]==pd)||(dup2(fd[1],pd)==pd)) - { - if (fd[1]!=pd) - { - close(fd[1]); - } - execl("/bin/sh","sh","-c",command,NULL); - close(pd); - } - exit(1); - break; - default: - close(fd[1]); - if (ret=fdopen(fd[0],type)) - { - return ret; - } - close(fd[0]); - break; - } - } - return NULL; + int fd[2]; + int pd; + FILE *ret; + if (!strcmp(type,"r")) + { + pd=STDOUT_FILENO; + } + else if (!strcmp(type,"w")) + { + pd=STDIN_FILENO; + } + else + { + return NULL; + } + if (pipe(fd)!=-1) + { + switch (fork()) + { + case -1: + close(fd[0]); + close(fd[1]); + break; + case 0: + close(fd[0]); + if ((fd[1]==pd)||(dup2(fd[1],pd)==pd)) + { + if (fd[1]!=pd) + { + close(fd[1]); + } + execl("/bin/sh","sh","-c",command,NULL); + close(pd); + } + exit(1); + break; + default: + close(fd[1]); + if (ret=fdopen(fd[0],type)) + { + return ret; + } + close(fd[0]); + break; + } + } + return NULL; } #endif /* defined(sgi) */ @@ -281,7 +281,7 @@ s2++; } if (*s1=='\0' && *s2=='\0') - return 0; + return 0; return (int) (*s1 - *s2); } #endif @@ -292,7 +292,7 @@ size_t len; if ((c = *find++) != 0) { - c = tolower(c); + c = tolower(c); len = strlen(find); do { do { @@ -347,15 +347,15 @@ int isqrt(int n) { - int result, sum, prev; - result = 0; - prev = sum = 1; - while (sum <= n) { - prev += 2; - sum += prev; - ++result; - } - return result; + int result, sum, prev; + result = 0; + prev = sum = 1; + while (sum <= n) { + prev += 2; + sum += prev; + ++result; + } + return result; } @@ -366,7 +366,7 @@ char *ltostr10(signed long n) { static char buf[12]; /* maximum size is n=-2 billion, i.e. 11 characters+1 - character for the trailing nul character */ + character for the trailing nul character */ snprintf(buf, sizeof(buf), "%ld", n); return buf; } @@ -554,18 +554,18 @@ struct stat statbuf; if (!filename || !*filename) - return; + return; strcpy (buf, filename); while ((cp = strchr (cp + 1, (int) '/'))) { - *cp = '\0'; - if (stat(buf, &statbuf) || !S_ISDIR (statbuf.st_mode)) { - if (mkdir (buf, SAVE_DIR_MODE)) { - LOG(llevError, "Cannot mkdir %s: %s\n", buf, strerror_local(errno)); - return; - } - } - *cp = '/'; + *cp = '\0'; + if (stat(buf, &statbuf) || !S_ISDIR (statbuf.st_mode)) { + if (mkdir (buf, SAVE_DIR_MODE)) { + LOG(llevError, "Cannot mkdir %s: %s\n", buf, strerror_local(errno)); + return; + } + } + *cp = '/'; } }