void reset_main(void) { int fd = tty_fd(); // man 4 console_codes: reset terminal is ESC (no left bracket) c xwrite(fd<0 ? 1 : fd, "\033c", 2); }
void expandhere(union node *arg, int fd) { herefd = fd; expandarg(arg, NULL, 0); xwrite(fd, stackblock(), expdest - stackblock()); }
int snap_log_write(uint32_t idx, const char *tag, unsigned char *sha1) { int fd, ret = -1; struct strbuf buf = STRBUF_INIT; struct snap_log log = { .idx = idx, .time = time(NULL) }; pstrcpy(log.tag, SD_MAX_SNAPSHOT_TAG_LEN, tag); memcpy(log.sha1, sha1, SHA1_DIGEST_SIZE); fd = open(snap_log_path, O_WRONLY | O_APPEND); if (fd < 0) { sd_err("%m"); goto out; } strbuf_reset(&buf); strbuf_add(&buf, &log, sizeof(log)); ret = xwrite(fd, buf.buf, buf.len); if (ret != buf.len) goto out_close; ret = 0; out_close: close(fd); out: strbuf_release(&buf); return ret; }
static int disp_too_much(t_list *st_list) { char read_buf[256]; char line[256]; char *buf; if ((buf = get_set_from_list(COMPLETION_CHOICE_STR)) && buf[0] == '0') return (-1); if (_list_sz(st_list) < MAX_CHOICE_DIP) return (-1); memset(read_buf, 0, 256); sprintf(line, "Display all %d possibilities ? (y||n)\n", _list_sz(st_list)); xwrite(1, line, strlen(line)); while (read_buf[0] != 'y' && read_buf[0] != 'n') { memset(read_buf, '\0', 256); xread(0, read_buf, sizeof(read_buf)); if (read_buf[0] == 'y' || read_buf[0] == '\t') return (TRUE); else if (read_buf[0] == 'n') { apply_term("up"); return (FALSE); } } return (TRUE); }
static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb, void *data) { unsigned char expn[4096]; size_t size = eltsize * nmemb; int posn = 0; struct object_request *obj_req = (struct object_request *)data; do { ssize_t retval = xwrite(obj_req->local, (char *) ptr + posn, size - posn); if (retval < 0) return posn; posn += retval; } while (posn < size); obj_req->stream.avail_in = size; obj_req->stream.next_in = ptr; do { obj_req->stream.next_out = expn; obj_req->stream.avail_out = sizeof(expn); obj_req->zret = inflate(&obj_req->stream, Z_SYNC_FLUSH); SHA1_Update(&obj_req->c, expn, sizeof(expn) - obj_req->stream.avail_out); } while (obj_req->stream.avail_in && obj_req->zret == Z_OK); data_received++; return size; }
static void chksum_and_xwrite(int fd, struct tar_header_t* hp) { /* POSIX says that checksum is done on unsigned bytes * (Sun and HP-UX gets it wrong... more details in * GNU tar source) */ const unsigned char *cp; int chksum, size; strcpy(hp->magic, "ustar "); /* Calculate and store the checksum (i.e., the sum of all of the bytes of * the header). The checksum field must be filled with blanks for the * calculation. The checksum field is formatted differently from the * other fields: it has 6 digits, a null, then a space -- rather than * digits, followed by a null like the other fields... */ memset(hp->chksum, ' ', sizeof(hp->chksum)); cp = (const unsigned char *) hp; chksum = 0; size = sizeof(*hp); do { chksum += *cp++; } while (--size); putOctal(hp->chksum, sizeof(hp->chksum)-1, chksum); /* Now write the header out to disk */ xwrite(fd, hp, sizeof(*hp)); }
/** * 向好友请求文件数据. * @param sock tcp socket * @param pal class PalInfo * @param packetno 好友消息的包编号 * @param fileid 文件ID标识 * @param offset 文件偏移量 * @return 消息发送成功与否 */ bool Command::SendAskData(int sock, PalInfo *pal, uint32_t packetno, uint32_t fileid, int64_t offset) { char attrstr[35]; //8+1+8+1+16 +1 =35 struct sockaddr_in addr; char *iptuxstr = "iptux"; snprintf(attrstr, 35, "%" PRIx32 ":%" PRIx32 ":%" PRIx64, packetno, fileid, offset); //IPMSG和Feiq的命令字段都是只有IPMSG_GETFILEDATA,使用(IPMSG_FILEATTACHOPT | IPMSG_GETFILEDATA) //会产生一些潜在的不兼容问题,所以在发往非iptux时只使用IPMSG_GETFILEDATA if(strstr(pal->version,iptuxstr)) CreateCommand(IPMSG_FILEATTACHOPT | IPMSG_GETFILEDATA, attrstr); else CreateCommand(IPMSG_GETFILEDATA, attrstr); ConvertEncode(pal->encode); bzero(&addr, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(IPTUX_DEFAULT_PORT); addr.sin_addr.s_addr = pal->ipv4; if (((connect(sock, (struct sockaddr *)&addr, sizeof(addr)) == -1) && (errno != EINTR)) || (xwrite(sock, buf, size) == -1)) return false; return true; }
static int write_config(void) { int fd, ret; void *jd; fd = open(config_path, O_DSYNC | O_WRONLY | O_CREAT, def_fmode); if (fd < 0) { eprintf("failed to open config file, %m\n"); return SD_RES_EIO; } jd = jrnl_begin(&config, sizeof(config), 0, config_path, jrnl_path); if (!jd) { eprintf("failed to write config data to journal, %m\n"); ret = SD_RES_EIO; goto out; } ret = xwrite(fd, &config, sizeof(config)); if (ret != sizeof(config)) { eprintf("failed to write config data, %m\n"); ret = SD_RES_EIO; } else ret = SD_RES_SUCCESS; jrnl_end(jd); out: close(fd); return ret; }
void expandhere(shinstance *psh, union node *arg, int fd) { psh->herefd = fd; expandarg(psh, arg, (struct arglist *)NULL, 0); xwrite(psh, fd, stackblock(psh), psh->expdest - stackblock(psh)); }
/** * Handle a signal in an async-safe fashion. The signal is written * to a pipe monitored in our main select() loop and will be handled * just as the other file descriptors there are. * @param signo the signal number */ static void pipehandler(int signo) { if(signalpipe[WRITE] > -1) { /* write is async safe. write the signal number to the pipe. */ xwrite(signalpipe[WRITE], &signo, sizeof(int)); } }
static void dopreload() { char buf[MAXBUF], *p; int fd, rv; snprintf(buf, sizeof(buf), "LD_PRELOAD=/tmp/tmplibckptXXXXXX"); p = buf+strlen("LD_PRELOAD="); fd = mkstemp(p); if(0 > fd){ fprintf(stderr, "ckpt I/O error\n"); exit(1); } rv = xwrite(fd, libckpt, libckptlen); if(0 > rv){ fprintf(stderr, "ckpt I/O error\n"); exit(1); } close(fd); if(0 > putenv(buf)){ fprintf(stderr, "ckpt error\n"); exit(1); } }
int do_internal_write_append (const char *path, const char *content, size_t size) { int fd; CHROOT_IN; fd = open (path, O_WRONLY|O_APPEND|O_CREAT|O_NOCTTY|O_CLOEXEC, 0666); CHROOT_OUT; if (fd == -1) { reply_with_perror ("open: %s", path); return -1; } if (xwrite (fd, content, size) == -1) { reply_with_perror ("write"); close (fd); return -1; } if (close (fd) == -1) { reply_with_perror ("close: %s", path); return -1; } return 0; }
int snap_log_write(uint32_t epoch, unsigned char *sha1, int user) { int fd, ret = -1; struct strbuf buf = STRBUF_INIT; struct snap_log log = { .epoch = epoch, .time = time(NULL) }; memcpy(log.sha1, sha1, SHA1_LEN); strbuf_addstr(&buf, farm_dir); strbuf_addf(&buf, "/%s", user ? "user_snap" : "sys_snap"); fd = open(buf.buf, O_WRONLY | O_APPEND); if (fd < 0) { dprintf("%m\n"); goto out; } strbuf_reset(&buf); strbuf_add(&buf, &log, sizeof(log)); ret = xwrite(fd, buf.buf, buf.len); if (ret != buf.len) ret = -1; close(fd); out: strbuf_release(&buf); return ret; }
static void writeheader(const char *path, struct stat *sb, int type) { struct tar_header_t header; int i, sum; memset(&header, 0, TAR_BLOCK_SIZE); strcpy(header.name, path); sprintf(header.mode, "%o", sb->st_mode & 0777); /* careful to not overflow fields! */ sprintf(header.uid, "%o", sb->st_uid & 07777777); sprintf(header.gid, "%o", sb->st_gid & 07777777); sprintf(header.size, "%o", (unsigned)sb->st_size); sprintf(header.mtime, "%llo", sb->st_mtime & 077777777777LL); header.typeflag = type; strcpy(header.magic, "ustar "); /* like GNU tar */ /* Calculate and store the checksum (the sum of all of the bytes of * the header). The checksum field must be filled with blanks for the * calculation. The checksum field is formatted differently from the * other fields: it has 6 digits, a NUL, then a space -- rather than * digits, followed by a NUL like the other fields... */ header.chksum[7] = ' '; sum = ' ' * 7; for (i = 0; i < TAR_BLOCK_SIZE; i++) sum += ((unsigned char*)&header)[i]; sprintf(header.chksum, "%06o", sum); xwrite(STDOUT_FILENO, &header, TAR_BLOCK_SIZE); }
static void release_write_buf(test_data *td, struct iovec* vecs, int n_vecs) { test_state *ps = (test_state *)td->data; assert(vecs == &ps->buffer && n_vecs == 1); xwrite(ps->sv[0], vecs[0].iov_base, vecs[0].iov_len); }
static void ATTRIBUTE_NORETURN convert(const smalluint flags) { size_t read_chars = 0, in_index = 0, out_index = 0, c, coded, last = -1; for (;;) { /* If we're out of input, flush output and read more input. */ if (in_index == read_chars) { if (out_index) { xwrite(STDOUT_FILENO, (char *)poutput, out_index); out_index = 0; } if ((read_chars = read(STDIN_FILENO, bb_common_bufsiz1, BUFSIZ)) <= 0) { if (write(STDOUT_FILENO, (char *)poutput, out_index) != out_index) bb_perror_msg(bb_msg_write_error); exit(EXIT_SUCCESS); } in_index = 0; } c = bb_common_bufsiz1[in_index++]; coded = pvector[c]; if ((flags & TR_OPT_delete) && pinvec[c]) continue; if ((flags & TR_OPT_squeeze_reps) && last == coded && (pinvec[c] || poutvec[coded])) continue; poutput[out_index++] = last = coded; } /* NOTREACHED */ }
int main_loop(int error, t_serv_info *servinfo, t_dest_info *dest) { fd_set readfds; fd_set writefds; int maxfd; int cs1; char *msg; msg = "BIENVENU\n"; FD_ZERO(&readfds); FD_ZERO(&writefds); if (select(servinfo->sock, &readfds, &writefds, NULL, NULL)) { printf("lool\n"); if (FD_ISSET(servinfo->sock, &readfds)) cs1=accept(servinfo->sock, (struct sockaddr *)&servinfo->sin_client, (socklen_t *)&servinfo->client_len); if (cs1 > 1) { xwrite(cs1, msg, strlen(msg)); logg(servinfo, dest); } } return (0); }
void xfclose(FILE *stream) { if (fclose(stream) == EOF) { xwrite(2, "fclose failed\n", 14); exit(EXIT_FAILURE); } }
static void print_outbuf(void) { int sz = cur_outbuf - outbuf; if (sz > 0) { xwrite(STDOUT_FILENO, outbuf, sz); cur_outbuf = outbuf; } }
void xpclose(FILE *stream) { if (pclose(stream) == -1) { xwrite(2, "pclose failed\n", 14); exit(EXIT_FAILURE); } }
void chmod_file(char *buffer, struct s_static_client *br) { char mode[CMD]; strcpy(mode, "SITE CHMOD "); get_info_c(&(mode[11]), buffer, my_strlen(buffer)); xwrite(br->s_fd, mode, my_strlen(mode)); }
void my_putstr(char *str) { int e; e = 0; while (str[e++]); xwrite(1, str, e); }
int write_file(int fd, u_char type, int seq_count, ulong len, u_char * content) { if (xwrite(fd, &type, sizeof(type)) < 0){ perror("xwrite:"); EXIT_TRACE1("xwrite type fails\n"); return -1; } if (xwrite(fd, &seq_count, sizeof(seq_count)) < 0){ EXIT_TRACE1("xwrite content fails\n"); } if (xwrite(fd, &len, sizeof(len)) < 0){ EXIT_TRACE1("xwrite content fails\n"); } if (xwrite(fd, content, len) < 0){ EXIT_TRACE1("xwrite content fails\n"); } return 0; }
void entering_passive(struct s_static_socket *br) { int pasvsock; size_t port; my_putstr("PASV Request\n"); if (br->pasv == -1 && br->ctrl == -1) { port = 1025; if ((pasvsock = init_pasv_socket(&port)) > -1) get_host_and_connect(br, pasvsock, port); else xwrite(br->cs, "425 Opening data connection failed\n", 35); } else xwrite(br->cs, "125 Data connection already open\n", 33); }
void restore_interactive(target_context_t *tc) { char c = '!'; if(strcmp(tc->medium, "serial")) target_set_medium(tc, "serial"); xwrite(tc->portfd, &c, 1); }
void write_signature(char *signature, int fd) { int count; count = -1; while (++count != TWO_OCT) xwrite(fd, &signature[count], 1); }
static void notify_parent(void) { /* * execvp failed. If possible, we'd like to let start_command * know, so failures like ENOENT can be handled right away; but * otherwise, finish_command will still report the error. */ xwrite(child_notifier, "", 1); }
void writeFinish(int fd){ u_char type = TYPE_FINISH; if (xwrite(fd, &type, sizeof(type)) < 0){ perror("xwrite:"); EXIT_TRACE1("xwrite type fails\n"); return; } CLOSE(fd); }
static int write_ar_archive(archive_handle_t *handle) { struct stat st; archive_handle_t *out_handle; char *temp_fn = NULL; xfstat(handle->src_fd, &st, handle->ar__name); /* if archive exists, create a new handle for output. * we create it in place of the old one. */ if (st.st_size != 0) { out_handle = init_handle(); #if !ENABLE_PLATFORM_MINGW32 xunlink(handle->ar__name); out_handle->src_fd = xopen(handle->ar__name, O_WRONLY | O_CREAT | O_TRUNC); #else /* can't unlink open file, create temporary output file */ temp_fn = xasprintf("%sXXXXXX", handle->ar__name); out_handle->src_fd = xmkstemp(temp_fn); #endif out_handle->accept = handle->accept; } else { out_handle = handle; } handle->ar__out = out_handle; xwrite(out_handle->src_fd, AR_MAGIC "\n", AR_MAGIC_LEN + 1); out_handle->offset += AR_MAGIC_LEN + 1; /* skip to the end of the archive if we have to append stuff */ if (st.st_size != 0) { handle->filter = filter_replaceable; handle->action_data = copy_data; unpack_ar_archive(handle); } while (write_ar_header(out_handle) == 0) continue; /* optional, since we exit right after we return */ if (ENABLE_FEATURE_CLEAN_UP || ENABLE_PLATFORM_MINGW32) { close(handle->src_fd); if (out_handle->src_fd != handle->src_fd) close(out_handle->src_fd); } #if ENABLE_PLATFORM_MINGW32 if ( temp_fn != NULL ) { xrename(temp_fn, handle->ar__name); free(temp_fn); } #endif return EXIT_SUCCESS; }
/** Catches thrown signals. Performs necessary cleanup to ensure database is * in a consistent state. * @param signum the thrown signal */ static void soft_interrupt_handler(int signum) { if(signum == SIGINT) { const char msg[] = "\nInterrupt signal received\n"; xwrite(STDERR_FILENO, msg, ARRAYSIZE(msg) - 1); } else { const char msg[] = "\nHangup signal received\n"; xwrite(STDERR_FILENO, msg, ARRAYSIZE(msg) - 1); } if(alpm_trans_interrupt(config->handle) == 0) { /* a transaction is being interrupted, don't exit pacman yet. */ return; } alpm_unlock(config->handle); /* output a newline to be sure we clear any line we may be on */ xwrite(STDOUT_FILENO, "\n", 1); _Exit(128 + signum); }