本文整理汇总了C++中xwrite函数的典型用法代码示例。如果您正苦于以下问题:C++ xwrite函数的具体用法?C++ xwrite怎么用?C++ xwrite使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xwrite函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: reset_main
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);
}
示例2: expandhere
void
expandhere(union node *arg, int fd)
{
herefd = fd;
expandarg(arg, NULL, 0);
xwrite(fd, stackblock(), expdest - stackblock());
}
示例3: snap_log_write
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;
}
示例4: disp_too_much
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);
}
示例5: fwrite_sha1_file
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;
}
示例6: chksum_and_xwrite
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));
}
示例7: snprintf
/**
* 向好友请求文件数据.
* @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;
}
示例8: write_config
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;
}
示例9: expandhere
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));
}
示例10: pipehandler
/**
* 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));
}
}
示例11: dopreload
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);
}
}
示例12: do_internal_write_append
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;
}
示例13: snap_log_write
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;
}
示例14: writeheader
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);
}
示例15: release_write_buf
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);
}