/* static int optboolean(const char *key, int opt) { const char * str = skynet_getenv(key); if (str == NULL) { skynet_setenv(key, opt ? "true" : "false"); return opt; } return strcmp(str,"true")==0; } */ static const char * optstring(const char *key,const char * opt) { const char * str = skynet_getenv(key); if (str == NULL) { if (opt) { skynet_setenv(key, opt); opt = skynet_getenv(key); } return opt; } return str; }
static int optboolean(const char *key, int opt) { const char * str = skynet_getenv(key); if (str == NULL) { skynet_setenv(key, opt ? "true" : "false"); return opt; } return strcmp(str,"true")==0; }
static int optint(const char *key, int opt) { const char * str = skynet_getenv(key); if (str == NULL) { char tmp[20]; sprintf(tmp,"%d",opt); skynet_setenv(key, tmp); return opt; } return strtol(str, NULL, 10); }
FILE * skynet_log_open(struct skynet_context * ctx, uint32_t handle) { const char * logpath = skynet_getenv("logpath"); if (logpath == NULL) return NULL; size_t sz = strlen(logpath); char tmp[sz + 16]; sprintf(tmp, "%s/%08x.log", logpath, handle); FILE *f = fopen(tmp, "ab"); if (f) { uint32_t starttime = skynet_gettime_fixsec(); uint32_t currenttime = skynet_gettime(); time_t ti = starttime + currenttime/100; skynet_error(ctx, "Open log file %s", tmp); fprintf(f, "open time: %u %s", currenttime, ctime(&ti)); fflush(f); } else { skynet_error(ctx, "Open log file %s fail", tmp); } return f; }