pspecos.c
来自「db.* (pronounced dee-be star) is an adva」· C语言 代码 · 共 903 行 · 第 1/2 页
C
903 行
len = strlen(key); while ((cp = psp_fileGets(ini->fh, ini->buf, INI_BUF_SIZE)) != NULL) { if (cp[0] == '[') return NULL; /* start of new section, key not found */ if (strnicmp(cp, key, len) == 0) { if ((cp = strchr(cp + len, '=')) == NULL) return NULL; /* No value specified */ while (isspace(*(++cp))) ; /* trim any trailing newlien */ if ((np = strchr(cp, '\n')) != NULL) *np = '\0'; return cp; } } return NULL;}/* ========================================================================== Read a short value from an INI file*/short psp_iniShort( PSP_INI ini, const DB_TCHAR *section, const DB_TCHAR *key, short def){ char *str; if (ini && (str = readINI((INI_ENTRY *) ini, section, key)) != NULL) return (short) strtoi(str); return def;}/* ========================================================================== Read a short value from an INI file*/size_t psp_iniString( PSP_INI ini, const DB_TCHAR *section, const DB_TCHAR *key, const DB_TCHAR *def, DB_TCHAR *buf, size_t len){ char *str; if (ini && (str = readINI((INI_ENTRY *) ini, section, key)) != NULL) strncpy(buf, str, len); else strncpy(buf, def, len); buf[len - 1] ='\0'; return strlen(buf);}/* ========================================================================== Suspend the current thread for the specified # of milliseconds*/void psp_sleep( unsigned long millisecs){ struct timespec tm1; struct timespec tm2; tm1.tv_sec = millisecs / 1000; tm1.tv_nsec = (millisecs % 1000) * 1000000; while (nanosleep(&tm1, &tm2) != 0) memcpy(&tm1, &tm2, sizeof(struct timespec));}/* =========================================================================== Return the process id*/unsigned int psp_get_pid( void){ return (unsigned int) getpid();}/* =========================================================================== Fork the process to begin daemon mode*/void psp_daemonInit( DB_TCHAR *name){ // ECOS doesn't support fork()ing}/* =========================================================================== Terminate running as a daemone. Nothing to do on Unix*/void psp_daemonTerm( void){}/* =========================================================================== Return a pointer to the first character of the file name portion of the supplied path*/char *psp_pathGetFile( const char *path){ char *cp; if ((cp = strrchr(path, DIRCHAR)) == NULL) return (char *) path; return cp + 1;}/* =========================================================================== Determine if the path is only a subdirectory (does not contain a file name)*/int psp_pathIsDir( const char *path){ size_t len; if (!path || !*path) return -1; len = strlen(path) - 1; if (path[len] == DIRCHAR) return 1; return 0;}/* =========================================================================== Split a path up into the subdirectory and file name components*/void psp_pathSplit( const char *path, char **dir, char **file){ char *cp; cp = strrchr(path, DIRCHAR); if (file) { if (cp && *(cp + 1)) *file = psp_strdup(cp + 1, 0); else *file = psp_strdup(path, 0); } if (dir) { if (cp) { *(cp + 1) = '\0'; *dir = psp_strdup(path, 0); } else *dir = NULL; }}/* =========================================================================== Return the path without any drive specifier*/char *psp_pathStripDrive( const char *path){ return (char *) path;}static char *dbtmp = "/tmp/";/* =========================================================================== Return the default temporary path*/char *psp_pathDefTmp( void){ return dbtmp;}typedef struct { DIR *entry; char *pattern;} DIR_ENTRY;/* =========================================================================== Open a directory for searching*/PSP_DIR psp_pathOpen( const char *path, const char *pattern){ DIR_ENTRY *dir; if ((dir = psp_getMemory(sizeof(DIR_ENTRY), 0)) == NULL) return NULL; if ((dir->entry = opendir(path)) == NULL) { psp_freeMemory(dir, 0); return NULL; } if ((dir->pattern = psp_strdup(pattern, 0)) == NULL) { psp_freeMemory(dir->entry, 0); psp_freeMemory(dir, 0); } return dir;}static int match( const char *str, const char *pattern){ char p; char s; while ((p = *pattern++) != '\0') { if (p == '*') { if ((p = *pattern++) == '\0') return 1; while (*str) { s = *str++; if (toupper(s) == toupper(p) && match(str, pattern)) return 1; } return 0; } if ((s = *str++) == '\0') return 0; if (p != '?' && toupper(p) != toupper(s)) return 0; } if (*str == '\0') return 1; return 0;}/* =========================================================================== Find next occurrence of requested name in path*/char *psp_pathNext( PSP_DIR dir){ struct dirent *ent; DIR_ENTRY *d; if (!dir) return NULL; d = (DIR_ENTRY *) dir; for ( ; ; ) { if ((ent = readdir(d->entry)) == NULL) return NULL; if (match(ent->d_name, d->pattern)) break; } return psp_strdup(ent->d_name, 0);}/* =========================================================================== Close directory searching*/void psp_pathClose( PSP_DIR dir){ DIR_ENTRY *d; if (dir) { d = (DIR_ENTRY *) dir; closedir(d->entry); psp_freeMemory(d->pattern, 0); psp_freeMemory(d, 0); }}/* =========================================================================== Return a random (hopefully) seed*/long psp_seed( void){ struct timespec tm; clock_gettime(CLOCK_REALTIME, &tm); return tm.tv_nsec;}/* =========================================================================== Return the current time in seconds*/long psp_timeSecs( void){ struct timespec tm; clock_gettime(CLOCK_REALTIME, &tm); return tm.tv_sec;}/* =========================================================================== Return the current time in milliseconds*/long psp_timeMilliSecs( void){ struct timespec tm; clock_gettime(CLOCK_REALTIME, &tm); return tm.tv_sec * 1000 + tm.tv_nsec / 1000000;}/* =========================================================================== Return the error number from the last call*/int psp_errno( void){ return errno;}/* =========================================================================== Return the contents of an environment variable*/char *psp_getenv( const char *var){ return getenv(var);}/* =========================================================================== Return a string that completely and uniquely defines a file (the "truename" of the file) so that the lock manager can correctly handle lock contention. On UNIX this means the device name on a host with the inode for that file in the following format: <devicepath>@<hostname>:<inode>*/char *psp_truename( const char *src, PSP_MEMTAG tag){ return psp_strdup(src, tag);}/* =========================================================================== Return the default lock manager name*/char *psp_defLockmgr( void){ return "lockmgr";}/* =========================================================================== Return the validity of the give lock manager name*/int psp_validLockmgr( const char *name){ char c; if (!name) return PSP_FAILED; while ((c = *name++) != '\0') { if (!(isalnum(c) || c == '_' || c == ':' || c == '.')) return 0; } return 1;}#if 0static INTERRUPT_FCN *interrupt_fcn = NULL;static void handler( int sig){ signal(SIGINT, SIG_IGN); if (interrupt_fcn) (*interrupt_fcn)(); signal(SIGINT, handler);}/* =========================================================================== Setup a function for handling interrupts*/int psp_handleInterrupt( INTERRUPT_FCN *fcn){ if (!fcn) { signal(SIGINT, SIG_IGN); return PSP_OKAY; } interrupt_fcn = fcn; signal(SIGINT, handler); return PSP_OKAY;}#endif/* =========================================================================== Get the current locale setting*/void psp_localeGet( DB_TCHAR *str, size_t len){ /* Not currently supported on UNIX */}/* =========================================================================== Set the current locale setting*/void psp_localeSet( const DB_TCHAR *str){ /* Not currently supported on UNIX */}/* =========================================================================== Prints an error to the screen and waits for input*/void psp_errPrint( const char *msg){ char ch; printf("%s\n", msg); printf("press <return> to continue "); do ch = (char) getchar(); while (ch != '\n' && ch != EOF);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?