本文整理汇总了C++中write_stdout函数的典型用法代码示例。如果您正苦于以下问题:C++ write_stdout函数的具体用法?C++ write_stdout怎么用?C++ write_stdout使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了write_stdout函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fields_fun
/* print all spaces, and only selected field numbers, on each line in turn */
bool_t fields_fun(void *user, byte_t *buf, size_t buflen) {
const char_t *p, *q, *r;
fields_fun_t *fft = (fields_fun_t *)user;
if( fft ) {
p = (char_t *)buf;
q = (char_t *)(buf + buflen);
while( p < q ) {
if( xml_whitespace(*p) ) {
fft->field_lock = FALSE;
/* all whitespace is printed */
r = skip_xml_whitespace(p, q);
write_stdout((byte_t *)p, (r - p));
if( memchr(p, '\n', r - p) ) {
fft->fno = 0; /* reset field number if newline */
}
p = r;
}
if( p < q ) {
if( !fft->field_lock ) {
fft->fno++;
fft->field_lock = TRUE;
}
/* find end of token */
r = find_xml_whitespace(p, q);
if( memberof_intervalmgr(fft->im, fft->fno) ) {
write_stdout((byte_t *)p, (r - p));
}
p = r;
}
}
return TRUE;
}
return FALSE;
}
示例2: write_stdout
int redir_t::redirect()
{
for(;;){
DWORD dw_avail = 0;
if(!::PeekNamedPipe(_h_stdout_read, nullptr, 0, 0, &dw_avail, nullptr))
break;
if(!dw_avail) return 1;
char buff[10240];
DWORD dw_read = 0;
if(!::ReadFile(_h_stdout_read, buff, min(_countof(buff)-1, dw_avail), &dw_read, nullptr))
break;
buff[dw_read] = '\0';
write_stdout(buff);
}
DWORD dw_err = ::GetLastError();
if(dw_err == ERROR_BROKEN_PIPE || dw_err == ERROR_NO_DATA) {
return 0;
}
return -1;
}
示例3: dfault
result_t dfault(void *user, const char_t *data, size_t buflen) {
parserinfo_cut_t *pinfo = (parserinfo_cut_t *)user;
if( pinfo ) {
write_stdout((byte_t *)data, buflen);
}
return PARSER_OK;
}
示例4: add_user_db
void add_user_db(char *username, char *passwd, char *homedirectory)
{
char *crypt_passwd;
if ((!(*username)) || (!(*passwd)) || (!(*homedirectory)))
{
write_stdout("<missing one or several arguments>\n");
exit(1);
}
crypt_passwd = crypt_pass(passwd);
if (my_strcmp(crypt_passwd, "") == 0)
{
write_stdout("<invalid argument>\n");
exit(1);
}
create_user_db(username, crypt_passwd, homedirectory);
}
示例5: main
int main(int argc, char *argv[])
{
vir_machine_init();
bootstrap();
os_init();
char order[800];
int i;
while (1) {
echo_mip4();
mips_want_get_string(order, 799);
switch(order[0]) {
case 'e':
sys_exec(order + 2);
break;
case 'f':
format_disk();
write_stdout("successfully formats the disk!\n", F_WHITE, B_BLACK);
break;
case 'c':
sys_create(order + 2);
write_stdout("successfully create file\n", F_WHITE, B_BLACK);
break;
case 'w': // copy the file to disk!
{
char *name = order + 2; // only one spaces !
sys_create(name);
int fid = sys_open(name);
int obj_id = open(name, O_RDONLY);
while (1) {
int buf;
if (read(obj_id, &buf, 1) == 0)
break;
char char_buf = (char)buf;
sys_write(fid, &char_buf, 1);
}
sys_close(fid);
write_stdout("successfully write file\n", F_WHITE, B_BLACK);
break;
}
}
}
return 0;
}
示例6: process_and_write_msg
process_and_write_msg(unsigned char account_len, char* account,
unsigned char protocol_len, char* protocol,
uint32_t msg_len, char* msg, uint32_t q_id) {
/* re-assemble message as single buffer */
unsigned char* buf;
unsigned char* buf_head;
if (msg == NULL || msg_len == 0) return;
uint32_t total_len = 4 + 4 + 1 + account_len + 1 + protocol_len + 4 + msg_len;
buf = malloc(total_len);
buf_head = buf;
*((uint32_t*)buf) = htonl(q_id);
buf += 4;
*((uint32_t*)buf) = htonl(total_len - 8);
buf += 4;
buf[0] = account_len;
buf++;
strncpy(buf, account, account_len);
buf += account_len;
buf[0] = protocol_len;
buf++;
strncpy(buf, protocol, protocol_len);
buf += protocol_len;
*((uint32_t*)buf) = htonl(msg_len);
buf += 4;
strncpy(buf, msg, msg_len);
uint32_t written = write_stdout(buf_head, total_len);
if (written == total_len) {
#ifdef __DEBUGGING
pthread_mutex_lock(&log_mutex);
fprintf(logfd, "%s", "Msg written to stdout\n");
fflush(logfd);
pthread_mutex_unlock(&log_mutex);
#endif
} else {
pthread_mutex_lock(&log_mutex);
fprintf(logfd, "Only wrote %u bytes to stdout, expected %u\n", written, total_len);
fprintf(logfd, "Failed on message from account %s protocol %s contents %s\n", account, protocol, msg);
fflush(logfd);
pthread_mutex_unlock(&log_mutex);
fprintf(stderr, "Only wrote %u bytes to stdout, expected %u\n", written, total_len);
}
free(buf_head);
}
示例7: main
int main(int argc, char **argv)
{
char c, *user, *pwd, *homedir;
user = "\0";
pwd = "\0";
homedir = "\0";
write_stdout("\n\t**ADD A USER IN DATABANK**\n\n");
write_stdout("<enter your login>\n");
while ((read(STDIN_FILENO, &c, 1) != -1) && (c != '\n'))
user = my_strconcat(user, c);
write_stdout("<enter your password>\n");
while ((read(STDIN_FILENO, &c, 1) != -1) && (c != '\n'))
pwd = my_strconcat(pwd, c);
write_stdout("<enter your homedirectory>\n");
while ((read(STDIN_FILENO, &c, 1) != -1) && (c != '\n'))
homedir = my_strconcat(homedir, c);
add_user_db(user, pwd, homedir);
write_stdout("<you are now a member of our databank>\n");
return 0;
}
示例8: print_permuted
/* Insert utf8chars at all positions in str */
void print_permuted(char *str, int len)
{
int i;
char *utfp = utf8chars[0];
int utfc = 0;
if (len > 0) {
while (utfp) {
for (i = 0; i <= len; i++) {
/* Before part */
write_stdout(str, i);
/* The unicode 2-byte character */
write_stdout(utfp, strlen(utfp));
/* After part */
if (i < len) {
write_stdout(&str[i], len - i);
}
write_stdout("\n", 1);
}
utfc++;
utfp = utf8chars[utfc];
}
}
}
示例9: _write
/*
write
Write a character to a file. `libc' subroutines will use this system routine for output to all files, including stdout
Returns -1 on error or number of bytes sent
*/
int _write(int file, char *ptr, int len)
{
switch (file)
{
case STDOUT_FILENO: /*stdout*/
return write_stdout((const unsigned char*)ptr, (unsigned int)len);
break;
case STDERR_FILENO: /* stderr */
return write_stderr((const unsigned char*)ptr, (unsigned int)len);
break;
default:
errno = EBADF;
return -1;
}
return 0;
}
示例10: write_query_response_s
void write_query_response_s(uint32_t id, unsigned char* msg, uint32_t msg_size) {
uint32_t buf_size = 0;
unsigned char* buf;
unsigned char* buf_head;
buf_size = 4 + 4 + msg_size;
buf = malloc(buf_size);
buf_head = buf;
pthread_mutex_lock(&log_mutex);
fprintf(logfd, "Writing query response to stdout -- id %u size %u msg size %u msg %s\n", id, buf_size, msg_size, msg);
fflush(logfd);
pthread_mutex_unlock(&log_mutex);
*((uint32_t*)buf) = htonl(id);
buf += 4;
*((uint32_t*)buf) = htonl((uint32_t)msg_size);
buf += 4;
memcpy(buf, msg, msg_size);
uint32_t written = buf_size;
written = write_stdout(buf_head, buf_size);
if (written == buf_size) {
pthread_mutex_lock(&log_mutex);
fprintf(logfd, "%s", "Msg written to stdout\n");
fflush(logfd);
pthread_mutex_unlock(&log_mutex);
} else {
pthread_mutex_lock(&log_mutex);
fprintf(logfd, "Only wrote %u bytes to stdout, expected %u\n", written, buf_size);
fflush(logfd);
pthread_mutex_unlock(&log_mutex);
fprintf(stderr, "Only wrote %u bytes to stdout, expected %u\n", written, buf_size);
}
free(buf_head);
}
示例11: accept
//.........这里部分代码省略.........
error, strerror(error));
return FALSE;
}
if(rc == 0)
/* timeout */
return TRUE;
if(FD_ISSET(fileno(stdin), &fds_read)) {
/* read from stdin, commands/data to be dealt with and possibly passed on
to the socket
protocol:
4 letter command + LF [mandatory]
4-digit hexadecimal data length + LF [if the command takes data]
data [the data being as long as set above]
Commands:
DATA - plain pass-thru data
*/
if(!read_stdin(buffer, 5))
return FALSE;
logmsg("Received %c%c%c%c (on stdin)",
buffer[0], buffer[1], buffer[2], buffer[3] );
if(!memcmp("PING", buffer, 4)) {
/* send reply on stdout, just proving we are alive */
if(!write_stdout("PONG\n", 5))
return FALSE;
}
else if(!memcmp("PORT", buffer, 4)) {
/* Question asking us what PORT number we are listening to.
Replies to PORT with "IPv[num]/[port]" */
sprintf((char *)buffer, "%s/%hu\n", ipv_inuse, port);
buffer_len = (ssize_t)strlen((char *)buffer);
snprintf(data, sizeof(data), "PORT\n%04zx\n", buffer_len);
if(!write_stdout(data, 10))
return FALSE;
if(!write_stdout(buffer, buffer_len))
return FALSE;
}
else if(!memcmp("QUIT", buffer, 4)) {
/* just die */
logmsg("quits");
return FALSE;
}
else if(!memcmp("DATA", buffer, 4)) {
/* data IN => data OUT */
if(!read_stdin(buffer, 5))
return FALSE;
buffer[5] = '\0';
buffer_len = (ssize_t)strtol((char *)buffer, NULL, 16);
if (buffer_len > (ssize_t)sizeof(buffer)) {
logmsg("ERROR: Buffer size (%zu bytes) too small for data size "
"(%zd bytes)", sizeof(buffer), buffer_len);
return FALSE;
示例12: main
//.........这里部分代码省略.........
" --ipv6\n"
" --bindonly\n"
" --port [port]\n"
" --connect [port]\n"
" --addr [address]");
return 0;
}
}
#ifdef WIN32
win32_init();
atexit(win32_cleanup);
setmode(fileno(stdin), O_BINARY);
setmode(fileno(stdout), O_BINARY);
setmode(fileno(stderr), O_BINARY);
#endif
install_signal_handlers();
#ifdef ENABLE_IPV6
if(!use_ipv6)
#endif
sock = socket(AF_INET, SOCK_STREAM, 0);
#ifdef ENABLE_IPV6
else
sock = socket(AF_INET6, SOCK_STREAM, 0);
#endif
if(CURL_SOCKET_BAD == sock) {
error = SOCKERRNO;
logmsg("Error creating socket: (%d) %s",
error, strerror(error));
write_stdout("FAIL\n", 5);
goto sockfilt_cleanup;
}
if(connectport) {
/* Active mode, we should connect to the given port number */
mode = ACTIVE;
#ifdef ENABLE_IPV6
if(!use_ipv6) {
#endif
memset(&me.sa4, 0, sizeof(me.sa4));
me.sa4.sin_family = AF_INET;
me.sa4.sin_port = htons(connectport);
me.sa4.sin_addr.s_addr = INADDR_ANY;
if (!addr)
addr = "127.0.0.1";
Curl_inet_pton(AF_INET, addr, &me.sa4.sin_addr);
rc = connect(sock, &me.sa, sizeof(me.sa4));
#ifdef ENABLE_IPV6
}
else {
memset(&me.sa6, 0, sizeof(me.sa6));
me.sa6.sin6_family = AF_INET6;
me.sa6.sin6_port = htons(connectport);
if (!addr)
addr = "::1";
Curl_inet_pton(AF_INET6, addr, &me.sa6.sin6_addr);
rc = connect(sock, &me.sa, sizeof(me.sa6));
}
#endif /* ENABLE_IPV6 */
if(rc) {
示例13: main
int
main (int argc, char **argv)
{
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
#ifdef PROGRESS_REPORT
struct cdjpeg_progress_mgr progress;
#endif
int file_index;
cjpeg_source_ptr src_mgr;
FILE * input_file;
FILE * output_file;
JDIMENSION num_scanlines;
/* On Mac, fetch a command line. */
#ifdef USE_CCOMMAND
argc = ccommand(&argv);
#endif
progname = argv[0];
if (progname == NULL || progname[0] == 0)
progname = "cjpeg"; /* in case C library doesn't provide it */
/* Initialize the JPEG compression object with default error handling. */
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo);
/* Add some application-specific error messages (from cderror.h) */
jerr.addon_message_table = cdjpeg_message_table;
jerr.first_addon_message = JMSG_FIRSTADDONCODE;
jerr.last_addon_message = JMSG_LASTADDONCODE;
/* Now safe to enable signal catcher. */
#ifdef NEED_SIGNAL_CATCHER
enable_signal_catcher((j_common_ptr) &cinfo);
#endif
/* Initialize JPEG parameters.
* Much of this may be overridden later.
* In particular, we don't yet know the input file's color space,
* but we need to provide some value for jpeg_set_defaults() to work.
*/
cinfo.in_color_space = JCS_RGB; /* arbitrary guess */
jpeg_set_defaults(&cinfo);
/* Scan command line to find file names.
* It is convenient to use just one switch-parsing routine, but the switch
* values read here are ignored; we will rescan the switches after opening
* the input file.
*/
file_index = parse_switches(&cinfo, argc, argv, 0, FALSE);
#ifdef TWO_FILE_COMMANDLINE
/* Must have either -outfile switch or explicit output file name */
if (outfilename == NULL) {
if (file_index != argc-2) {
fprintf(stderr, "%s: must name one input and one output file\n",
progname);
usage();
}
outfilename = argv[file_index+1];
} else {
if (file_index != argc-1) {
fprintf(stderr, "%s: must name one input and one output file\n",
progname);
usage();
}
}
#else
/* Unix style: expect zero or one file name */
if (file_index < argc-1) {
fprintf(stderr, "%s: only one input file\n", progname);
usage();
}
#endif /* TWO_FILE_COMMANDLINE */
/* Open the input file. */
if (file_index < argc) {
if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {
fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]);
exit(EXIT_FAILURE);
}
} else {
/* default input file is stdin */
input_file = read_stdin();
}
/* Open the output file. */
if (outfilename != NULL) {
if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {
fprintf(stderr, "%s: can't open %s\n", progname, outfilename);
exit(EXIT_FAILURE);
}
} else {
/* default output file is stdout */
output_file = write_stdout();
}
#ifdef PROGRESS_REPORT
//.........这里部分代码省略.........
示例14: main
//.........这里部分代码省略.........
fprintf(stderr, "%s: must name one input and one output file\n",
progname);
usage();
}
}
}
#else
/* Unix style: expect zero or one file name */
if (file_index < argc-1) {
fprintf(stderr, "%s: only one input file\n", progname);
usage();
}
#endif /* TWO_FILE_COMMANDLINE */
/* Open the input file. */
if (file_index < argc) {
if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {
fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]);
exit(EXIT_FAILURE);
}
} else {
/* default input file is stdin */
input_file = read_stdin();
}
/* Open the output file. */
if (outfilename != NULL) {
if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {
fprintf(stderr, "%s: can't open %s\n", progname, outfilename);
exit(EXIT_FAILURE);
}
} else if (!memdst) {
/* default output file is stdout */
output_file = write_stdout();
}
#ifdef PROGRESS_REPORT
start_progress_monitor((j_common_ptr) &cinfo, &progress);
#endif
/* Figure out the input file format, and set up to read it. */
src_mgr = select_file_type(&cinfo, input_file);
src_mgr->input_file = input_file;
/* Read the input file header to obtain file size & colorspace. */
(*src_mgr->start_input) (&cinfo, src_mgr);
/* Now that we know input colorspace, fix colorspace-dependent defaults */
#if JPEG_RAW_READER
if (!is_jpeg)
#endif
jpeg_default_colorspace(&cinfo);
/* Adjust default compression parameters by re-parsing the options */
file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);
/* Specify data destination for compression */
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
if (memdst)
jpeg_mem_dest(&cinfo, &outbuffer, &outsize);
else
#endif
jpeg_stdio_dest(&cinfo, output_file);
/* Start compressor */
jpeg_start_compress(&cinfo, TRUE);
示例15: main
int
main (int argc, char **argv)
{
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
#ifdef PROGRESS_REPORT
struct cdjpeg_progress_mgr progress;
#endif
int file_index;
djpeg_dest_ptr dest_mgr = NULL;
FILE * input_file;
FILE * output_file;
unsigned char *inbuffer = NULL;
unsigned long insize = 0;
JDIMENSION num_scanlines;
/* On Mac, fetch a command line. */
#ifdef USE_CCOMMAND
argc = ccommand(&argv);
#endif
progname = argv[0];
if (progname == NULL || progname[0] == 0)
progname = "djpeg"; /* in case C library doesn't provide it */
/* Initialize the JPEG decompression object with default error handling. */
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
/* Add some application-specific error messages (from cderror.h) */
jerr.addon_message_table = cdjpeg_message_table;
jerr.first_addon_message = JMSG_FIRSTADDONCODE;
jerr.last_addon_message = JMSG_LASTADDONCODE;
/* Insert custom marker processor for COM and APP12.
* APP12 is used by some digital camera makers for textual info,
* so we provide the ability to display it as text.
* If you like, additional APPn marker types can be selected for display,
* but don't try to override APP0 or APP14 this way (see libjpeg.txt).
*/
jpeg_set_marker_processor(&cinfo, JPEG_COM, print_text_marker);
jpeg_set_marker_processor(&cinfo, JPEG_APP0+12, print_text_marker);
/* Scan command line to find file names. */
/* It is convenient to use just one switch-parsing routine, but the switch
* values read here are ignored; we will rescan the switches after opening
* the input file.
* (Exception: tracing level set here controls verbosity for COM markers
* found during jpeg_read_header...)
*/
file_index = parse_switches(&cinfo, argc, argv, 0, FALSE);
#ifdef TWO_FILE_COMMANDLINE
/* Must have either -outfile switch or explicit output file name */
if (outfilename == NULL) {
if (file_index != argc-2) {
fprintf(stderr, "%s: must name one input and one output file\n",
progname);
usage();
}
outfilename = argv[file_index+1];
} else {
if (file_index != argc-1) {
fprintf(stderr, "%s: must name one input and one output file\n",
progname);
usage();
}
}
#else
/* Unix style: expect zero or one file name */
if (file_index < argc-1) {
fprintf(stderr, "%s: only one input file\n", progname);
usage();
}
#endif /* TWO_FILE_COMMANDLINE */
/* Open the input file. */
if (file_index < argc) {
if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {
fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]);
exit(EXIT_FAILURE);
}
} else {
/* default input file is stdin */
input_file = read_stdin();
}
/* Open the output file. */
if (outfilename != NULL) {
if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {
fprintf(stderr, "%s: can't open %s\n", progname, outfilename);
exit(EXIT_FAILURE);
}
} else {
/* default output file is stdout */
output_file = write_stdout();
}
#ifdef PROGRESS_REPORT
start_progress_monitor((j_common_ptr) &cinfo, &progress);
//.........这里部分代码省略.........