![]() |
![]()
| ![]() |
![]()
NAMExt_redirect() - Redirect stdin, stdout and stderr if corresponding argument isn't NULL xt_strlupper() - Copy string and convert lower case to uppper LIBRARY#include <xtend/string.h> -lxtend SYNOPSISsize_t xt_strlupper(char *dest, const char *src, size_t dest_size) ARGUMENTSsrc Pointer to null-terminated string to be copied dest Pointer to a character array to receive the copy dest_size Size of the destination array DESCRIPTIONThis function redirects the stdin, stdout, and stderr of the current process to the files named by the corresponding arguments. The original file streams are not preserved. If you need to restore any of these streams to their original state, they must be saved (e.g. using dup(), dup2(), or ttyname()) prior to calling xt_redirect(). Author: Jason W. Bacon ***************************************************************************/ void xt_redirect( char *infile, /* If not NULL, stdin is redirected from this file */ char *outfile, /* If not NULL, stdout is redirected to this file */ char *errfile /* If not NULL, stderr is redirected to this file */ ) { if (infile != NULL) { close(0); if ( open(infile, O_RDONLY) == -1 ) fprintf(stderr,"xt_redirect(): Cannot open infile: %s.n",infile); } if (outfile != NULL) { close(1); if ( open(outfile, O_WRONLY | O_CREAT | O_TRUNC, 0600) == -1 ) fprintf(stderr,"xt_redirect(): Cannot open outfile: %s.n",outfile); } if (errfile != NULL) { close(2); if ( strcmp(errfile,outfile) == 0 ) { if ( dup(1) == -1 ) fprintf(stderr,"xt_redirect(): Cannot open errfile: %s.n",errfile); } else { if ( open(errfile, O_WRONLY | O_CREAT | O_TRUNC, 0600) == -1 ) fprintf(stderr,"xt_redirect(): Cannot open errfile: %s.n",errfile); } } } xt_strlupper(3) copies a string from src to dest, up to a maximum of dest_size - 1 characters. It behaves exactly like strlcpy(3), except that any lower case characters in the string are converted to upper case. RETURN VALUESSize of the src string. If this differs from dest_size, then we knoiw the copy is truncated. EXAMPLESchar src[] = "Some text", dest [DEST_SIZE + 1]; if ( xt_strlupper(dest, src, DEST_SIZE + 1) != DEST_SIZE + 1 ) SEE ALSOxt_strllower(3), strlcpy(3), strlcat(3)
|