void parse_backup_messages( dle_t *dle, int mesgin) { int goterror; char *line; amfree(errorstr); for(; (line = areads(mesgin)) != NULL; free(line)) { process_dumpline(line); } if(errno) { error(_("error [read mesg pipe: %s]"), strerror(errno)); /*NOTREACHED*/ } goterror = check_result(mesgfd); if(errorstr) { error(_("error [%s]"), errorstr); /*NOTREACHED*/ } else if(dump_size == -1) { error(_("error [no backup size line]")); /*NOTREACHED*/ } program->end_backup(dle, goterror); fdprintf(mesgfd, _("%s: size %ld\n"), get_pname(), dump_size); fdprintf(mesgfd, _("%s: end\n"), get_pname()); }
void caserd(void) { lgf++; skip(0); getname(); if (!iflg) { if (quiet) { #ifdef NROFF echo_off(); flusho(); #endif /* NROFF */ fdprintf(stderr, "\007"); /*bell*/ } else { if (nextf[0]) { fdprintf(stderr, "%s:", nextf); } else { fdprintf(stderr, "\007"); /*bell*/ } } } collect(); tty++; pushi(-1, PAIR('r','d'), 0); }
static int smtp_server(CLI *c) { char line[STRLEN]; if(RFC2487(c, c->local_rfd.fd)==0) return 0; /* Return if RFC 2487 is not used */ if(fdscanf(c, c->remote_fd.fd, "220%[^\n]", line)!=1) { s_log(LOG_ERR, "Unknown server welcome"); return -1; } if(fdprintf(c, c->local_wfd.fd, "220%s + stunnel", line)<0) return -1; if(fdscanf(c, c->local_rfd.fd, "EHLO %[^\n]", line)!=1) { s_log(LOG_ERR, "Unknown client EHLO"); return -1; } if(fdprintf(c, c->local_wfd.fd, "250-%s Welcome", line)<0) return -1; if(fdprintf(c, c->local_wfd.fd, "250 STARTTLS")<0) return -1; if(fdscanf(c, c->local_rfd.fd, "STARTTLS", line)<0) { s_log(LOG_ERR, "STARTTLS expected"); return -1; } if(fdprintf(c, c->local_wfd.fd, "220 Go ahead")<0) return -1; return 0; }
/* Store the logf log to logf.txt in the .rockbox directory. The order of the * entries will be "reversed" so that the most recently logged entry is on the * top of the file */ bool logfdump(void) { int fd; splashf(HZ, "Log File Dumped"); /* nothing to print ? */ if(logfindex == 0 && !logfwrap) /* nothing is logged just yet */ return false; fd = open(ROCKBOX_DIR "/logf.txt", O_CREAT|O_WRONLY|O_TRUNC); if(-1 != fd) { int i; if(logfwrap) i = logfindex; else i = 0; do { if(logfbuffer[i]=='\0') fdprintf(fd, "\n"); else fdprintf(fd, "%c", logfbuffer[i]); i++; if(i >= MAX_LOGF_SIZE) i = 0; } while(i != logfindex); close(fd); } return false; }
static int smtp_client(CLI *c) { char line[STRLEN]; do { /* Copy multiline greeting */ if(fdscanf(c, c->remote_fd.fd, "%[^\n]", line)<0) return -1; if(fdprintf(c, c->local_wfd.fd, "%s", line)<0) return -1; } while(strncasecmp(line,"220-",4)==0); if(fdprintf(c, c->remote_fd.fd, "EHLO localhost")<0) /* Send an EHLO command */ return -1; do { /* Skip multiline reply */ if(fdscanf(c, c->remote_fd.fd, "%[^\n]", line)<0) return -1; } while(strncasecmp(line,"250-",4)==0); if(strncasecmp(line,"250 ",4)!=0) { /* Error */ s_log(LOG_ERR, "Remote server is not RFC 1425 compliant"); return -1; } if(fdprintf(c, c->remote_fd.fd, "STARTTLS")<0) /* Send STARTTLS command */ return -1; do { /* Skip multiline reply */ if(fdscanf(c, c->remote_fd.fd, "%[^\n]", line)<0) return -1; } while(strncasecmp(line,"220-",4)==0); if(strncasecmp(line,"220 ",4)!=0) { /* Error */ s_log(LOG_ERR, "Remote server is not RFC 2487 compliant"); return -1; } return 0; }
static void do_show_all(int client, char *buf) { int err; DIR *dirp; char *c, name[256]; buf += 8; // Skip over command while (*buf && (*buf == ' ')) buf++; if (*buf) { // Name provided strcpy(name, buf); } else { strcpy(name, "."); } fdprintf(client, "<INFO> show .jpg files in directory %s\n",name); dirp = opendir( name ); if( dirp == NULL ) { fdprintf(client, "Can't open directory \"%s\"\n", name); return; } for(;;) { struct dirent *entry = readdir( dirp ); struct stat sbuf; char fullname[PATH_MAX]; if( entry == NULL ) break; if( name[0] ) { strcpy(fullname, name ); if( !(name[0] == '/' && name[1] == 0 ) ) strcat(fullname, "/" ); } else fullname[0] = 0; strcat(fullname, entry->d_name ); err = stat( fullname, &sbuf ); if( err < 0 ) { fdprintf(client, "<ERROR> Can't access \"%s\":", fullname); if( errno == ENOSYS ) { fdprintf(client, " <no status available>"); } else { fdprintf(client, "%s\n", strerror(errno)); } } else { #if 0 if (/* hack: !S_ISREG(sbuf.st_mode)*/ (sbuf.st_mode & 0x8000) == 0) { continue; } #endif if ((c = rindex(fullname, '.')) != (char *)NULL) { if (strcmp(c, ".jpg") == 0) { show_jpeg(client, fullname, show_time); } } } } err = closedir( dirp ); }
static int export_common(Environment &env, bool export_or_unexport, const std::vector<std::string> &tokens, const fdmask &fds) { const char *name = export_or_unexport ? "Export" : "Unexport"; bool _r = false; bool _s = false; bool error = false; auto argv = getopt(tokens, [&](char c){ switch(tolower(c)) { case 'r': _r = true; break; case 's': _s = true; break; default: fdprintf(stderr, "### %s - \"-%c\" is not an option.\n", name, c); error = true; break; } }); if (error) { fdprintf(stderr, "# Usage - %s [-r | -s | name...]\n", name); return 1; } if (argv.empty()) { if (_r && _s) goto conflict; // list of exported vars. // -r will generate unexport commands for exported variables. // -s will only print the names. name = export_or_unexport ? "Export " : "Unexport "; for (const auto &kv : env) { const std::string& vname = kv.first; if (kv.second == export_or_unexport) fdprintf(stdout, "%s%s\n", _s ? "" : name, quote(vname).c_str()); } return 0; } else { // mark as exported. if (_r || _s) goto conflict; for (std::string s : argv) { auto iter = env.find(s); if (iter != env.end()) iter->second = export_or_unexport; } return 0; } conflict: fdprintf(stderr, "### %s - Conflicting options or parameters were specified.\n", name); fdprintf(stderr, "# Usage - %s [-r | -s | name...]\n", name); return 1; }
int builtin_set(Environment &env, const std::vector<std::string> &tokens, const fdmask &fds) { // set var name -- set // set var -- just print the value // 3.5 supports -e to also export it. //io_helper io(fds); if (tokens.size() == 1) { for (const auto &kv : env) { std::string name = quote(kv.first); std::string value = quote(kv.second); fdprintf(stdout, "Set %s%s %s\n", bool(kv.second) ? "-e " : "", name.c_str(), value.c_str()); } return 0; } if (tokens.size() == 2) { std::string name = tokens[1]; auto iter = env.find(name); if (iter == env.end()) { fdprintf(stderr, "### Set - No variable definition exists for %s.\n", name.c_str()); return 2; } name = quote(name); std::string value = quote(iter->second); fdprintf(stdout, "Set %s%s %s\n", bool(iter->second) ? "-e " : "", name.c_str(), value.c_str()); return 0; } bool exported = false; if (tokens.size() == 4 && tokens[1] == "-e") { exported = true; } if (tokens.size() > 3 && !exported) { fdputs("### Set - Too many parameters were specified.\n", stderr); fdputs("# Usage - set [name [value]]\n", stderr); return 1; } std::string name = tokens[1+exported]; std::string value = tokens[2+exported]; env.set(name, value, exported); return 0; }
void print_escaped(char *str, int len) { int i = 0; char c[2] = {0}, tmp[2] = {0}; char *hex_nums = "0123456789ABCDEF"; while (len--) { c[0] = str[i++]; switch (c[0]) { case '"': fdprintf(STDOUT, "\\\""); break; case '\\': fdprintf(STDOUT, "\\\\"); break; case '/': fdprintf(STDOUT, "\\/"); break; case '\b': fdprintf(STDOUT, "\\b"); break; case '\f': fdprintf(STDOUT, "\\f"); break; case '\n': fdprintf(STDOUT, "\\n"); break; case '\r': fdprintf(STDOUT, "\\r"); break; case '\t': fdprintf(STDOUT, "\\t"); break; default: fdprintf(STDOUT, "%s", c); break; } } }
static bool settings_write_config(const char* filename, int options) { int i; int fd; char value[MAX_PATH]; fd = open(filename,O_CREAT|O_TRUNC|O_WRONLY, 0666); if (fd < 0) return false; fdprintf(fd, "# .cfg file created by rockbox %s - " "http://www.rockbox.org\r\n\r\n", rbversion); for(i=0; i<nb_settings; i++) { if (settings[i].cfg_name == NULL) continue; value[0] = '\0'; if (settings[i].flags & F_DEPRECATED) continue; switch (options) { case SETTINGS_SAVE_CHANGED: if (!is_changed(i)) continue; break; case SETTINGS_SAVE_SOUND: if ((settings[i].flags&F_SOUNDSETTING) == 0) continue; break; case SETTINGS_SAVE_THEME: if ((settings[i].flags&F_THEMESETTING) == 0) continue; break; #ifdef HAVE_RECORDING case SETTINGS_SAVE_RECPRESETS: if ((settings[i].flags&F_RECSETTING) == 0) continue; break; #endif #if CONFIG_CODEC == SWCODEC case SETTINGS_SAVE_EQPRESET: if ((settings[i].flags&F_EQSETTING) == 0) continue; break; #endif } cfg_to_string(i, value, MAX_PATH); fdprintf(fd,"%s: %s\r\n",settings[i].cfg_name,value); } /* for(...) */ close(fd); return true; }
static void do_get(int client, char *buf) { char *fn, *sn, *data; #ifdef CYGPKG_FS_RAM char _fn[PATH_MAX]; #endif int fd, len, err; struct sockaddr_in srvr_addr; buf += 3; // Skip over command fn = strtok(buf, " ,"); sn = strtok(NULL, " ,"); if ((fn == (char *)NULL) || (sn == (char *)NULL)) { fdprintf(client, "usage: get <file> <server>\n"); return; } // For now, only numeric IP addresses if (!inet_aton(sn, &srvr_addr.sin_addr)) { fdprintf(client, "Can't get host info: %s\n", sn); return; } srvr_addr.sin_port = 0; if ((data = (char *)malloc(0x100000)) == (char *)NULL) { fdprintf(client, "Can't allocate temp buffer\n"); return; } if ((len = tftp_get(fn, &srvr_addr, data, 0x100000, TFTP_OCTET, &err)) > 0) { fdprintf(client, "Read %d bytes\n", len); fd = open(fn, O_RDWR|O_CREAT); if (fd > 0) { err = write(fd, data, len); if (err != len) { fdprintf(client, "Error writing data\n"); } close(fd); } else { fdprintf(client, "Can't create \"%s\"\n", fn); } #ifdef CYGPKG_FS_RAM sprintf(_fn, "/%s", fn); fd = open(_fn, O_RDWR|O_CREAT); if (fd > 0) { err = write(fd, data, len); if (err != len) { fdprintf(client, "Error writing data\n"); } close(fd); } else { fdprintf(client, "Can't create \"%s\"\n", _fn); } #endif } else { fdprintf(client, "Error reading data\n"); } free(data); }
static void do_line(void *data) { struct double_list *dlist = data; if (TT.state>1 && *dlist->data != TT.state) fdprintf(TT.state == 2 ? 2 : TT.fileout, "%s\n", dlist->data+(TT.state>3 ? 1 : 0)); if (PATCH_DEBUG) fdprintf(2, "DO %d: %s\n", TT.state, dlist->data); free(dlist->data); free(dlist); }
static void outtp(tchar i) { #ifndef NROFF int j = cbits(i); #ifdef EUC if (iscopy(i)) fdprintf(ptid, "%lc", j); else #endif /* EUC */ fdprintf(ptid, "%c", j); #endif }
/* Inputs: Outputs: Effects: */ void output_tbl(int fd, struct user_priority *ppri_tbl) { int limit; fdprintf(fd, "%d\n%d:\n", ppri_tbl->deflt, ppri_tbl->deflt_limit); printlist_setup (" ", "\n", "", ""); for (limit = PRI_MIN; limit <= PRI_MAX; limit++) if (ppri_tbl->users[limit - PRI_MIN]) { fdprintf(fd, "%d:", limit); fdprintlist(fd, ppri_tbl->users[limit - PRI_MIN]); } }
void fdprintsdn(int fd, SCALED sdn) { register char *dec = "9999.999", *z; if (sdn.val <= 0) return; (void)fdprintf (fd, "%s", NB(print_prefix)); /* * Let's try to be a bit clever in dealing with decimal * numbers. If the number is an integer, don't print * a decimal point. If it isn't an integer, strip trailing * zeros from the fraction part, and don't print more * than the thousandths place. */ if (-1000. < sdn.val && sdn.val < 10000.) { /* * Printing 0 will give us 0.000. */ sprintf (dec, "%.3f", sdn.val); /* * Skip zeroes from the end until we hit * '.' or not-0. If we hit '.', clobber it; * if we hit not-0, it has to be in fraction * part, so leave it. */ z = dec + strlen(dec) - 1; while (*z == '0' && *z != '.') z--; if (*z == '.') *z = '\0'; else *++z = '\0'; (void)fdprintf(fd, "%s", dec); } else (void)fdprintf(fd, "%.3f", sdn.val); if (sdn.sc == 'i' || sdn.sc == 'c') fdputc(sdn.sc, fd); (void)fdprintf(fd, "%s%s", NB(print_suffix), NB(print_newline)); return; }
static void do_rm(int client, char *buf) { char *fn; buf += 2; // Skip over command fn = strtok(buf, " ,"); if (fn == (char *)NULL) { fdprintf(client, "usage: rm <file>\n"); return; } if (unlink(fn) < 0) { fdprintf(client, "Can't remove \"%s\": %s\n", fn, strerror(errno)); } }
static int manager_action(char *action, char *fmt, ...) { struct ast_mansession *s; char tmp[4096]; va_list ap; s = &session; fdprintf(s->fd, "Action: %s\r\n", action); va_start(ap, fmt); vsnprintf(tmp, sizeof(tmp), fmt, ap); va_end(ap); write(s->fd, tmp, strlen(tmp)); fdprintf(s->fd, "\r\n"); return 0; }
void kty_double_to_string(kty_item_t *item) { int tmp; double val; val = item->item.i_double; tmp = (int) val; if (val < 0.0 && tmp == 0) fdprintf(STDOUT, "-"); fdprintf(STDOUT, "%d.", tmp); tmp = ((int)(val * 100.0)) % 100; if (tmp < 0) tmp = -tmp; fdprintf(STDOUT, "%02d", tmp); }
static sfsistat cb_body(SMFICTX *ctx, u_char *chunk, size_t size) { struct context *context; if ((context = (struct context *)smfi_getpriv(ctx)) == NULL) { msg(LOG_ERR, NULL, "cb_body: smfi_getpriv"); return (SMFIS_ACCEPT); } for (; size > 0; size--, chunk++) { context->buf[context->pos] = *chunk; if (context->buf[context->pos] == '\n' || context->pos == sizeof(context->buf) - 1) { if (context->pos > 0 && context->buf[context->pos - 1] == '\r') context->buf[context->pos - 1] = 0; else context->buf[context->pos] = 0; context->pos = 0; msg(LOG_DEBUG, context, "cb_body('%s')", context->buf); if (context->fd >= 0 && context->lines < 1000) { fdprintf(context->fd, "%s\r\n", context->buf); context->lines++; } } else context->pos++; } return (SMFIS_CONTINUE); }
int builtin_catenate(Environment &env, const std::vector<std::string> &tokens, const fdmask &fds) { if (tokens.size() == 1) { int rv = cat_helper(stdin, stdout); if (rv) fdputs("### Catenate - I/O Error\n", stderr); return rv; } for (const auto &s : make_offset_range(tokens, 1)) { std::string path = ToolBox::MacToUnix(s); int fd = open(path.c_str(), O_RDONLY); if (fd < 0) { fdprintf(stderr, "### Catenate - Unable to open \"%s\".\n", path.c_str()); return 1; } int rv = cat_helper(fd, stdout); close(fd); if (rv) { fdputs("### Catenate - I/O Error\n", stderr); return rv; } } return 0; }
void cgc_bbs_rx(const uint8_t *data, cgc_size_t count) { char str[101]; #ifdef PATCHED if (count > sizeof(str)-1) count = sizeof(str)-1; #endif cgc_memcpy(str, data, count); str[count] = 0; // make sure string is NULL-terminated if (cgc_strlen(str) == 0) return; #ifdef DEBUG fdprintf(STDERR, "%s\n", str); #endif if (g_state.state == S_MENU) { cgc_handle_menu(str); } else if (g_state.state == S_LIST_THREAD || g_state.state == S_LIST_MESSAGE) { cgc_handle_list(str); } else if (g_state.state == S_POST_WAIT_TOPIC || g_state.state == S_POST_WAIT_BODY) { cgc_handle_post(str); } if (g_state.state == S_MENU) cgc_bbs_menu(); }
// ZZZ: the socket listening thread loops in this function. It calls the registered // packet handler when it gets something. static int receive_thread_function(void*) { while(true) { // We listen with a timeout so we can shut ourselves down when needed. int theResult = SDLNet_CheckSockets(sSocketSet, 1000); if(!sKeepListening) break; if(theResult > 0) { theResult = SDLNet_UDP_Recv(sSocket, sUDPPacketBuffer); if(theResult > 0) { if(take_mytm_mutex()) { ddpPacketBuffer.protocolType = kPROTOCOL_TYPE; ddpPacketBuffer.sourceAddress = sUDPPacketBuffer->address; ddpPacketBuffer.datagramSize = sUDPPacketBuffer->len; // Hope the other guy is done using whatever's in there! // (As I recall, all uses happen in sPacketHandler and its progeny, so we should be fine.) memcpy(ddpPacketBuffer.datagramData, sUDPPacketBuffer->data, sUDPPacketBuffer->len); sPacketHandler(&ddpPacketBuffer); release_mytm_mutex(); } else fdprintf("could not take mytm mutex - incoming packet dropped"); } } } return 0; }
static void send_string(const char *str) { #ifdef DEBUG fdprintf(STDERR, "%s\n", str); #endif cgc_modem_output((void *)str, cgc_strlen(str)); }
static void print_reason(int fd, int reason) { register int i; #define P(BIT,MSG) if (chkprinter_result & BIT) fdprintf(fd, MSG) for (i = 0; N_Reason[i].reason != -1; i++) if (N_Reason[i].reason == reason) { if (reason == MDENYDEST && chkprinter_result) i++; if (reason == MDENYMEDIA && chkprinter_result) i++; fdprintf(fd, N_Msg[10], N_Reason[i].msg); if (reason == MDENYDEST && chkprinter_result) { P (PCK_TYPE, "\tprinter type\n"); P (PCK_CHARSET, "\tcharacter set\n"); P (PCK_CPI, "\tcharacter pitch\n"); P (PCK_LPI, "\tline pitch\n"); P (PCK_WIDTH, "\tpage width\n"); P (PCK_LENGTH, "\tpage length\n"); P (PCK_BANNER, "\tno banner\n"); } break; } return; }
static void RunJob(const char *user, CronLine *line) { char mailFile[128]; int mailFd = -1; line->cl_Pid = 0; line->cl_MailFlag = 0; if (line->cl_MailTo) { /* open mail file - owner root so nobody can screw with it. */ snprintf(mailFile, sizeof(mailFile), "%s/cron.%s.%d", TMPDIR, user, getpid()); mailFd = open(mailFile, O_CREAT | O_TRUNC | O_WRONLY | O_EXCL | O_APPEND, 0600); if (mailFd >= 0) { line->cl_MailFlag = 1; fdprintf(mailFd, "To: %s\nSubject: cron: %s\n\n", user, line->cl_Shell); line->cl_MailPos = lseek(mailFd, 0, SEEK_CUR); } else { crondlog(ERR20 "cannot create mail file %s for user %s, " "discarding output", mailFile, user); } } ForkJob(user, line, mailFd, DEFAULT_SHELL, "-c", line->cl_Shell, mailFile); }
void queue_network_speaker_data(byte* inData, short inLength) { if(inLength > 0) { if(sSoundDataBuffers.getCountOfElements() > 0) { // Fill out a descriptor for a new chunk of storage NetworkSpeakerSoundBufferDescriptor theBufferDesc; theBufferDesc.mData = sSoundDataBuffers.peek(); sSoundDataBuffers.dequeue(); theBufferDesc.mLength = inLength; theBufferDesc.mFlags = kSoundDataIsDisposable; // and copy the data memcpy(theBufferDesc.mData, inData, inLength); // If we're just turning on, prime the queue with a few buffers of noise. if(!sSpeakerIsOn) { for(int i = 0; i < kNumPumpPrimes; i++) { sSoundBuffers.enqueue(sNoiseBufferDesc); } sSpeakerIsOn = true; } // Enqueue the actual sound data. sSoundBuffers.enqueue(theBufferDesc); } else { fdprintf("No sound data buffer space available - audio discarded"); } } }
static void do_cmd(int client, char *buf) { char *cp = buf+strlen(buf)-1; while ((*cp == '\n') || (*cp == '\r')) { *cp-- = '\0'; // Remove trailing terminators } printf("Command: %s\n", buf); if (strncmp(buf, "ls", 2) == 0) { do_ls(client, buf); } else if (strncmp(buf, "show_all", 8) == 0) { do_show_all(client, buf); } else if (strncmp(buf, "show", 4) == 0) { do_show(client, buf); } else if (strncmp(buf, "time", 4) == 0) { do_time(client, buf); } else if (strncmp(buf, "get", 3) == 0) { do_get(client, buf); } else if (strncmp(buf, "rm", 2) == 0) { do_rm(client, buf); } else { fdprintf(client, "Unknown command: %s\n", buf); } }
static void start_one_job(const char *user, CronLine *line) { char mailFile[128]; int mailFd = -1; line->cl_pid = 0; line->cl_empty_mail_size = 0; if (line->cl_mailto) { /* Open mail file (owner is root so nobody can screw with it) */ snprintf(mailFile, sizeof(mailFile), "%s/cron.%s.%d", CRON_DIR, user, getpid()); mailFd = open(mailFile, O_CREAT | O_TRUNC | O_WRONLY | O_EXCL | O_APPEND, 0600); if (mailFd >= 0) { fdprintf(mailFd, "To: %s\nSubject: cron: %s\n\n", line->cl_mailto, line->cl_cmd); line->cl_empty_mail_size = lseek(mailFd, 0, SEEK_CUR); } else { bb_error_msg("can't create mail file %s for user %s, " "discarding output", mailFile, user); } } line->cl_pid = fork_job(user, mailFd, line, /*sendmail?*/ 0); if (mailFd >= 0) { if (line->cl_pid <= 0) { unlink(mailFile); } else { /* rename mail-file based on pid of process */ char *mailFile2 = xasprintf("%s/cron.%s.%d", CRON_DIR, user, (int)line->cl_pid); rename(mailFile, mailFile2); // TODO: xrename? free(mailFile2); } } }
static void ForkJob(const char *user, CronLine * line, int mailFd, const char *prog, const char *cmd, const char *arg, const char *mailf) { /* Fork as the user in question and run program */ pid_t pid = fork(); line->cl_Pid = pid; if (pid == 0) { /* CHILD */ /* Change running state to the user in question */ if (ChangeUser(user) < 0) { exit(0); } #ifdef FEATURE_DEBUG_OPT if (DebugOpt) { crondlog("\005Child Running %s\n", prog); } #endif if (mailFd >= 0) { dup2(mailFd, mailf != NULL); dup2((mailf ? mailFd : 1), 2); close(mailFd); } execl(prog, prog, cmd, arg, NULL); crondlog("\024unable to exec, user %s cmd %s %s %s\n", user, prog, cmd, arg); if (mailf) { fdprintf(1, "Exec failed: %s -c %s\n", prog, arg); } exit(0); } else if (pid < 0) { /* FORK FAILED */ crondlog("\024couldn't fork, user %s\n", user); line->cl_Pid = 0; if (mailf) { remove(mailf); } } else if (mailf) { /* PARENT, FORK SUCCESS * rename mail-file based on pid of process */ char mailFile2[128]; snprintf(mailFile2, sizeof(mailFile2), TMPDIR "/cron.%s.%d", user, pid); rename(mailf, mailFile2); } /* * Close the mail file descriptor.. we can't just leave it open in * a structure, closing it later, because we might run out of descriptors */ if (mailFd >= 0) { close(mailFd); } }
void kty_object_to_string(kty_item_t *item, int depth) { int count = 0; htbl_t *table; entry_t *entry; fdprintf(STDOUT, "{"); table = item->item.i_object; if (table) { fdprintf(STDOUT, "\n"); for (entry = table->head; entry != NULL ; entry = entry->next) { if (count > 0) fdprintf(STDOUT, ",\n"); count++; print_indent(depth + 1); fdprintf(STDOUT, "\""); print_escaped(entry->key, cgc_strlen(entry->key)); fdprintf(STDOUT, "\": "); kty_print_item(entry->val, depth + 1); } } if (count > 0) { fdprintf(STDOUT, "\n"); print_indent(depth); } fdprintf(STDOUT, "}"); }