# Lars Wirzenius <liw@iki.fi>
check() {
- printf "$2" | ./isutf8 -q
- ret=$?
- if [ $ret != $1 ]
- then
- echo "Failure:"
- echo " input: $2"
- echo " expected: $1"
- echo " got: $ret"
- fi
+ printf "$2" | ./isutf8 -q
+ ret=$?
+ if [ $ret != $1 ]; then
+ echo "Failure:"
+ echo " input: $2"
+ echo " expected: $1"
+ echo " got: $ret"
+ fi
}
check 0 ''
* Made ifdata support -h and print usage on unknown options.
* Cleaned up ifdata's behavior when asked to print info for nonexistant
devices. Still needs improvement.
+ * Indentation improvements.
-- Joey Hess <joeyh@debian.org> Tue, 7 Mar 2006 21:54:45 -0500
<refentry>
- <refentryinfo>
- <author>
- <firstname>Joey</firstname>
- <surname>Hess</surname>
- </author>
- <date>2006-03-07</date>
- </refentryinfo>
+ <refentryinfo>
+ <author>
+ <firstname>Joey</firstname>
+ <surname>Hess</surname>
+ </author>
+ <date>2006-03-07</date>
+ </refentryinfo>
- <refmeta>
- <refentrytitle>ifdata</refentrytitle>
- <manvolnum>1</manvolnum>
- </refmeta>
+ <refmeta>
+ <refentrytitle>ifdata</refentrytitle>
+ <manvolnum>1</manvolnum>
+ </refmeta>
- <refnamediv>
- <refname>ifdata</refname>
- <refpurpose>get network interface info without parsing ifconfig output</refpurpose>
- </refnamediv>
+ <refnamediv>
+ <refname>ifdata</refname>
+ <refpurpose>get network interface info without
+ parsing ifconfig output</refpurpose>
+ </refnamediv>
- <refsynopsisdiv>
- <cmdsynopsis>
- <command>ifdata</command>
- <arg>options</arg>
- <arg><replaceable>iface</replaceable></arg>
- </cmdsynopsis>
- </refsynopsisdiv>
+ <refsynopsisdiv>
+ <cmdsynopsis>
+ <command>ifdata</command>
+ <arg>options</arg>
+ <arg><replaceable>iface</replaceable></arg>
+ </cmdsynopsis>
+ </refsynopsisdiv>
- <refsect1>
- <title>DESCRIPTION</title>
-
- <para><command>ifdata</command> can be used to check for the existence
- of a network interface, or to get information abut the interface, such
- as its IP address. Unlike <command>ifconfig</command> or <command>ip</command>,
- <command>ifdata</command> has simple to parse output that is designed
- to be easily used by a shell script.</para>
-
- </refsect1>
+ <refsect1>
+ <title>DESCRIPTION</title>
+
+ <para>
+ <command>ifdata</command> can be used to check for
+ the existence of a network interface, or to get
+ information abut the interface, such as its IP
+ address. Unlike <command>ifconfig</command> or
+ <command>ip</command>, <command>ifdata</command>
+ has simple to parse output that is designed to be
+ easily used by a shell script.
+ </para>
+
+ </refsect1>
- <refsect1>
- <title>OPTIONS</title>
-
- <variablelist>
-
- <varlistentry>
- <term><option>-h</option></term>
- <listitem>
- <para>Print out a help summary.</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term><option>-e</option></term>
- <listitem>
- <para>Test to see if the interface exists. ifdata will exit
- nonzero if the interface does not exist.</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term><option>-p</option></term>
- <listitem>
- <para>Prints out the whole configuration of the interface.</para>
- </listitem>
- </varlistentry>
+ <refsect1>
+ <title>OPTIONS</title>
+
+ <variablelist>
+
+ <varlistentry>
+ <term><option>-h</option></term>
+ <listitem>
+ <para>Print out a help summary.</para>
+ </listitem>
+ </varlistentry>
- <varlistentry>
- <term><option>-pe</option></term>
- <listitem>
- <para>Prints "yes" or "no" if the interface exists or not.</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term><option>-pa</option></term>
- <listitem>
- <para>Prints the IPv4 address of the interface.</para>
- </listitem>
- </varlistentry>
+ <varlistentry>
+ <term><option>-e</option></term>
+ <listitem>
+ <para>Test to see if the interface exists,
+ exit nonzero if it does not.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><option>-p</option></term>
+ <listitem>
+ <para>Prints out the whole configuration of
+ the interface.</para>
+ </listitem>
+ </varlistentry>
- <varlistentry>
- <term><option>-pn</option></term>
- <listitem>
- <para>Prints the netmask of the interface.</para>
- </listitem>
- </varlistentry>
+ <varlistentry>
+ <term><option>-pe</option></term>
+ <listitem>
+ <para>Prints "yes" or "no" if the interface
+ exists or not.</para>
+ </listitem>
+ </varlistentry>
- <varlistentry>
- <term><option>-pN</option></term>
- <listitem>
- <para>Prints the network address of the interface.</para>
- </listitem>
- </varlistentry>
+ <varlistentry>
+ <term><option>-pa</option></term>
+ <listitem>
+ <para>Prints the IPv4 address of the
+ interface.</para>
+ </listitem>
+ </varlistentry>
- <varlistentry>
- <term><option>-pb</option></term>
- <listitem>
- <para>Prints the broadcast address of the interface.</para>
- </listitem>
- </varlistentry>
+ <varlistentry>
+ <term><option>-pn</option></term>
+ <listitem>
+ <para>Prints the netmask of the
+ interface.</para>
+ </listitem>
+ </varlistentry>
- <varlistentry>
- <term><option>-pm</option></term>
- <listitem>
- <para>Prints the MTU of the interface.</para>
- </listitem>
- </varlistentry>
+ <varlistentry>
+ <term><option>-pN</option></term>
+ <listitem>
+ <para>Prints the network address of the
+ interface.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><option>-pb</option></term>
+ <listitem>
+ <para>Prints the broadcast address of the
+ interface.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><option>-pm</option></term>
+ <listitem>
+ <para>Prints the MTU of the interface.</para>
+ </listitem>
+ </varlistentry>
- <varlistentry>
- <term><option>-pf</option></term>
- <listitem>
- <para>Prints the flags of the interface.</para>
- </listitem>
- </varlistentry>
+ <varlistentry>
+ <term><option>-pf</option></term>
+ <listitem>
+ <para>Prints the flags of the
+ interface.</para>
+ </listitem>
+ </varlistentry>
- <varlistentry>
- <term><option>-si</option></term>
- <listitem>
- <para>Prints out all the input statistics of the interface.</para>
- </listitem>
- </varlistentry>
+ <varlistentry>
+ <term><option>-si</option></term>
+ <listitem>
+ <para>Prints out all the input statistics
+ of the interface.</para>
+ </listitem>
+ </varlistentry>
- <varlistentry>
- <term><option>-sip</option></term>
- <listitem>
- <para>Prints the number of input packets.</para>
- </listitem>
- </varlistentry>
+ <varlistentry>
+ <term><option>-sip</option></term>
+ <listitem>
+ <para>Prints the number of input packets.</para>
+ </listitem>
+ </varlistentry>
- <varlistentry>
- <term><option>-sib</option></term>
- <listitem>
- <para>Prints the number of input bytes.</para>
- </listitem>
- </varlistentry>
+ <varlistentry>
+ <term><option>-sib</option></term>
+ <listitem>
+ <para>Prints the number of input bytes.</para>
+ </listitem>
+ </varlistentry>
- <varlistentry>
- <term><option>-sie</option></term>
- <listitem>
- <para>Prints the number of input errors.</para>
- </listitem>
- </varlistentry>
+ <varlistentry>
+ <term><option>-sie</option></term>
+ <listitem>
+ <para>Prints the number of input errors.</para>
+ </listitem>
+ </varlistentry>
- <varlistentry>
- <term><option>-sid</option></term>
- <listitem>
- <para>Prints the number of input drops.</para>
- </listitem>
- </varlistentry>
+ <varlistentry>
+ <term><option>-sid</option></term>
+ <listitem>
+ <para>Prints the number of input drops.</para>
+ </listitem>
+ </varlistentry>
- <varlistentry>
- <term><option>-sif</option></term>
- <listitem>
- <para>Prints the number of input fifo overruns.</para>
- </listitem>
- </varlistentry>
+ <varlistentry>
+ <term><option>-sif</option></term>
+ <listitem>
+ <para>Prints the number of input fifo overruns.</para>
+ </listitem>
+ </varlistentry>
- <varlistentry>
- <term><option>-sic</option></term>
- <listitem>
- <para>Print the number of input compress.</para>
- </listitem>
- </varlistentry>
+ <varlistentry>
+ <term><option>-sic</option></term>
+ <listitem>
+ <para>Print the number of input compress.</para>
+ </listitem>
+ </varlistentry>
- <varlistentry>
- <term><option>-sim</option></term>
- <listitem>
- <para>Prints the number of input multicast.</para>
- </listitem>
- </varlistentry>
+ <varlistentry>
+ <term><option>-sim</option></term>
+ <listitem>
+ <para>Prints the number of input multicast.</para>
+ </listitem>
+ </varlistentry>
- <varlistentry>
- <term><option>-so</option></term>
- <listitem>
- <para>Prints out all the output statistics of the interface.</para>
- </listitem>
- </varlistentry>
+ <varlistentry>
+ <term><option>-so</option></term>
+ <listitem>
+ <para>Prints out all the output statistics
+ of the interface.</para>
+ </listitem>
+ </varlistentry>
- <varlistentry>
- <term><option>-sop</option></term>
- <listitem>
- <para>Prints the number of output packets.</para>
- </listitem>
- </varlistentry>
+ <varlistentry>
+ <term><option>-sop</option></term>
+ <listitem>
+ <para>Prints the number of output packets.</para>
+ </listitem>
+ </varlistentry>
- <varlistentry>
- <term><option>-sob</option></term>
- <listitem>
- <para>Prints the number of output bytes.</para>
- </listitem>
- </varlistentry>
+ <varlistentry>
+ <term><option>-sob</option></term>
+ <listitem>
+ <para>Prints the number of output bytes.</para>
+ </listitem>
+ </varlistentry>
- <varlistentry>
- <term><option>-soe</option></term>
- <listitem>
- <para>Prints the number of output errors.</para>
- </listitem>
- </varlistentry>
+ <varlistentry>
+ <term><option>-soe</option></term>
+ <listitem>
+ <para>Prints the number of output errors.</para>
+ </listitem>
+ </varlistentry>
- <varlistentry>
- <term><option>-sod</option></term>
- <listitem>
- <para>Prints the number of output drops.</para>
- </listitem>
- </varlistentry>
+ <varlistentry>
+ <term><option>-sod</option></term>
+ <listitem>
+ <para>Prints the number of output drops.</para>
+ </listitem>
+ </varlistentry>
- <varlistentry>
- <term><option>-sof</option></term>
- <listitem>
- <para>Prints the number of output fifo overruns.</para>
- </listitem>
- </varlistentry>
+ <varlistentry>
+ <term><option>-sof</option></term>
+ <listitem>
+ <para>Prints the number of output fifo overruns.</para>
+ </listitem>
+ </varlistentry>
- <varlistentry>
- <term><option>-sox</option></term>
- <listitem>
- <para>Print the number of output collisions.</para>
- </listitem>
- </varlistentry>
+ <varlistentry>
+ <term><option>-sox</option></term>
+ <listitem>
+ <para>Print the number of output collisions.</para>
+ </listitem>
+ </varlistentry>
- <varlistentry>
- <term><option>-soc</option></term>
- <listitem>
- <para>Prints the number of output carrier loss.</para>
- </listitem>
- </varlistentry>
+ <varlistentry>
+ <term><option>-soc</option></term>
+ <listitem>
+ <para>Prints the number of output carrier loss.</para>
+ </listitem>
+ </varlistentry>
- <varlistentry>
- <term><option>-som</option></term>
- <listitem>
- <para>Prints the number of output multicast.</para>
- </listitem>
- </varlistentry>
+ <varlistentry>
+ <term><option>-som</option></term>
+ <listitem>
+ <para>Prints the number of output multicast.</para>
+ </listitem>
+ </varlistentry>
- </variablelist>
-
- </refsect1>
-
+ </variablelist>
+ </refsect1>
</refentry>
* I'm pretty sure there is a fancy trick to do this without a loop,
* but I'm too tired to figure it out now. --liw
*/
-static int high_ones(int c)
-{
- int n;
+static int high_ones(int c) {
+ int n;
- for (n = 0; (c & 0x80) == 0x80; c <<= 1)
- ++n;
- return n;
+ for (n = 0; (c & 0x80) == 0x80; c <<= 1)
+ ++n;
+ return n;
}
-static int is_utf8_byte_stream(FILE *file, char *filename, int quiet)
-{
- int c, n, remaining_bytes;
- unsigned long line, col;
-
- remaining_bytes = 0;
- line = 1;
- col = 1;
- while ((c = getc(file)) != EOF) {
- n = high_ones(c);
- if (remaining_bytes > 0) {
- if (n == 1) {
- --remaining_bytes;
- if (remaining_bytes == 0)
- ++col;
- } else
- goto error;
- } else if (n == 0) {
- /* 7-bit character, skip, but adjust position */
- if (c == '\n') {
- ++line;
- col = 1;
- } else
- ++col;
- } else if (n == 1)
- goto error; /* wrong place for continuation byte */
- else
- remaining_bytes = n - 1; /* start of multi-byte sequence */
- }
- if (remaining_bytes > 0)
- goto error;
- return 1;
-
+static int is_utf8_byte_stream(FILE *file, char *filename, int quiet) {
+ int c, n, remaining_bytes;
+ unsigned long line, col;
+
+ remaining_bytes = 0;
+ line = 1;
+ col = 1;
+ while ((c = getc(file)) != EOF) {
+ n = high_ones(c);
+ if (remaining_bytes > 0) {
+ if (n == 1) {
+ --remaining_bytes;
+ if (remaining_bytes == 0)
+ ++col;
+ } else
+ goto error;
+ } else if (n == 0) {
+ /* 7-bit character, skip, but adjust position */
+ if (c == '\n') {
+ ++line;
+ col = 1;
+ } else
+ ++col;
+ } else if (n == 1)
+ goto error; /* wrong place for continuation byte */
+ else
+ remaining_bytes = n - 1; /* start of multi-byte sequence */
+ }
+ if (remaining_bytes > 0)
+ goto error;
+ return 1;
+
error:
- if (!quiet) {
- printf("%s: line %lu, col %lu: invalid UTF-8 code\n",
- filename, line, col);
- }
- return 0;
+ if (!quiet) {
+ printf("%s: line %lu, col %lu: invalid UTF-8 code\n",
+ filename, line, col);
+ }
+ return 0;
}
-static void usage(const char *program_name)
-{
- printf("Usage: %s [-hq] [--help] [--quiet] [file ...]\n", program_name);
- printf("Check whether input files are valid UTF-8.\n");
- printf("This is version %s.\n", VERSION);
+static void usage(const char *program_name) {
+ printf("Usage: %s [-hq] [--help] [--quiet] [file ...]\n", program_name);
+ printf("Check whether input files are valid UTF-8.\n");
+ printf("This is version %s.\n", VERSION);
}
-int main(int argc, char **argv)
-{
- int i, ok;
- FILE *file;
+int main(int argc, char **argv) {
+ int i, ok;
+ FILE *file;
- int quiet;
- struct option options[] = {
- { "help", no_argument, NULL, 'h' },
- { "quiet", no_argument, &quiet, 1 },
- };
- int opt;
-
- quiet = 0;
-
- while ((opt = getopt_long(argc, argv, "hq", options, NULL)) != -1) {
- switch (opt) {
- case 0:
- break;
-
- case 'h':
- usage(argv[0]);
- exit(0);
- break;
-
- case 'q':
- quiet = 1;
- break;
+ int quiet;
+ struct option options[] = {
+ { "help", no_argument, NULL, 'h' },
+ { "quiet", no_argument, &quiet, 1 },
+ };
+ int opt;
+
+ quiet = 0;
+
+ while ((opt = getopt_long(argc, argv, "hq", options, NULL)) != -1) {
+ switch (opt) {
+ case 0:
+ break;
+
+ case 'h':
+ usage(argv[0]);
+ exit(0);
+ break;
+
+ case 'q':
+ quiet = 1;
+ break;
- case '?':
- exit(EXIT_FAILURE);
+ case '?':
+ exit(EXIT_FAILURE);
- default:
- abort();
- }
- }
+ default:
+ abort();
+ }
+ }
- if (optind == argc)
- ok = is_utf8_byte_stream(stdin, "stdin", quiet);
- else {
- ok = 1;
- for (i = optind; i < argc; ++i) {
- file = fopen(argv[i], "r");
- if (file == NULL) {
- fprintf(stderr, "isutf8: %s: error %d: %s\n",
- argv[i], errno, strerror(errno));
- ok = 0;
- } else {
- ok = is_utf8_byte_stream(file, argv[i], quiet) && ok;
- (void) fclose(file);
- }
- }
- }
-
- if (ok)
- exit(0);
- exit(EXIT_FAILURE);
+ if (optind == argc)
+ ok = is_utf8_byte_stream(stdin, "stdin", quiet);
+ else {
+ ok = 1;
+ for (i = optind; i < argc; ++i) {
+ file = fopen(argv[i], "r");
+ if (file == NULL) {
+ fprintf(stderr, "isutf8: %s: error %d: %s\n",
+ argv[i], errno, strerror(errno));
+ ok = 0;
+ } else {
+ ok = is_utf8_byte_stream(file, argv[i], quiet) && ok;
+ (void) fclose(file);
+ }
+ }
+ }
+
+ if (ok)
+ exit(0);
+ exit(EXIT_FAILURE);
}
[]>
<refentry>
+ <refentryinfo>
+ <address>
+ <email>liw@iki.fi</email>
+ </address>
+ <author>
+ <firstname>Lars</firstname>
+ <surname>Wirzenius</surname>
+ </author>
+ <date>2006-02-19</date>
+ </refentryinfo>
- <refentryinfo>
- <address>
- <email>liw@iki.fi</email>
- </address>
- <author>
- <firstname>Lars</firstname>
- <surname>Wirzenius</surname>
- </author>
- <date>2006-02-19</date>
- </refentryinfo>
+ <refmeta>
+ <refentrytitle>isutf8</refentrytitle>
+ <manvolnum>1</manvolnum>
+ </refmeta>
- <refmeta>
- <refentrytitle>isutf8</refentrytitle>
- <manvolnum>1</manvolnum>
- </refmeta>
-
- <refnamediv>
- <refname>isutf8</refname>
- <refpurpose>check whether files are valid UTF-8</refpurpose>
- </refnamediv>
-
- <refsynopsisdiv>
- <cmdsynopsis>
- <command>isutf8</command>
- <arg><option>-hq</option></arg>
- <arg><option>--help</option></arg>
- <arg><option>--quiet</option></arg>
- <group choice="opt">
- <arg rep="repeat"><replaceable>file</replaceable></arg>
- </group>
- </cmdsynopsis>
- </refsynopsisdiv>
-
- <refsect1>
- <title>DESCRIPTION</title>
-
- <para><command>isutf8</command> checks whether files are
- syntactically valid UTF-8. Input is either files named on the
- command line, or the standard input. Notices about files with
- invalid UTF-8 are printed to standard output.</para>
-
- </refsect1>
-
- <refsect1>
- <title>OPTIONS</title>
-
- <variablelist>
-
- <varlistentry>
- <term><option>-h</option></term>
- <term><option>--help</option></term>
- <listitem>
- <para>Print out a help summary.</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term><option>-q</option></term>
- <term><option>--quiet</option></term>
- <listitem>
- <para>Don't print messages telling which files are
- invalid UTF-8, merely indicate it with the exit
- status.</para>
- </listitem>
- </varlistentry>
-
- </variablelist>
-
- </refsect1>
-
- <refsect1>
- <title>EXIT STATUS</title>
-
- <para>If the file is valid UTF-8, the exit status is zero. If the
- file is not valid UTF-8, or there is some error, the exit status is
- non-zero.</para>
-
- </refsect1>
-
- <refsect1>
- <title>SEE ALSO</title>
-
- <para>
- <citerefentry>
- <refentrytitle>utf8</refentrytitle><manvolnum>7</manvolnum>
- </citerefentry>
- </para>
-
- </refsect1>
+ <refnamediv>
+ <refname>isutf8</refname>
+ <refpurpose>check whether files are valid UTF-8</refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <cmdsynopsis>
+ <command>isutf8</command>
+ <arg><option>-hq</option></arg>
+ <arg><option>--help</option></arg>
+ <arg><option>--quiet</option></arg>
+ <group choice="opt">
+ <arg rep="repeat"><replaceable>file</replaceable></arg>
+ </group>
+ </cmdsynopsis>
+ </refsynopsisdiv>
+
+ <refsect1>
+ <title>DESCRIPTION</title>
+
+ <para><command>isutf8</command> checks whether files are
+ syntactically valid UTF-8. Input is either files named on the
+ command line, or the standard input. Notices about files with
+ invalid UTF-8 are printed to standard output.</para>
+
+ </refsect1>
+
+ <refsect1>
+ <title>OPTIONS</title>
+
+ <variablelist>
+
+ <varlistentry>
+ <term><option>-h</option></term>
+ <term><option>--help</option></term>
+ <listitem>
+ <para>Print out a help summary.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><option>-q</option></term>
+ <term><option>--quiet</option></term>
+ <listitem>
+ <para>Don't print messages telling which files are
+ invalid UTF-8, merely indicate it with the exit
+ status.</para>
+ </listitem>
+ </varlistentry>
+
+ </variablelist>
+
+ </refsect1>
+
+ <refsect1>
+ <title>EXIT STATUS</title>
+
+ <para>If the file is valid UTF-8, the exit status is zero.
+ If the file is not valid UTF-8, or there is some
+ error, the exit status is non-zero.</para>
+
+ </refsect1>
+
+ <refsect1>
+ <title>SEE ALSO</title>
+
+ <para>
+ <citerefentry>
+ <refentrytitle>utf8</refentrytitle><manvolnum>7</manvolnum>
+ </citerefentry>
+ </para>
+
+ </refsect1>
</refentry>
#include <string.h>
void usage() {
- printf("sponge <file>: suck in all input from stdin and write it to <file>");
- exit(0);
+ printf("sponge <file>: suck in all input from stdin and write it to <file>");
+ exit(0);
}
int main(int argc, char **argv) {
- char *buf, *bufstart;
- size_t bufsize = 8192;
- size_t bufused = 0;
- ssize_t i = 0;
- int outfd;
- if (argc != 2) {
- usage();
- }
+ char *buf, *bufstart;
+ size_t bufsize = 8192;
+ size_t bufused = 0;
+ ssize_t i = 0;
+ int outfd;
+
+ if (argc != 2) {
+ usage();
+ }
- bufstart = buf = malloc(bufsize);
- if (!buf) {
- perror("malloc");
- exit(1);
- }
+ bufstart = buf = malloc(bufsize);
+ if (!buf) {
+ perror("malloc");
+ exit(1);
+ }
- while ((i = read(0, buf, bufsize - bufused)) > 0) {
- bufused = bufused+i;
- if (bufused == bufsize) {
- bufsize *= 2;
- bufstart = realloc(bufstart, bufsize);
- if (!bufstart) {
- perror("realloc");
- exit(1);
- }
+ while ((i = read(0, buf, bufsize - bufused)) > 0) {
+ bufused = bufused+i;
+ if (bufused == bufsize) {
+ bufsize *= 2;
+ bufstart = realloc(bufstart, bufsize);
+ if (!bufstart) {
+ perror("realloc");
+ exit(1);
+ }
- buf = bufstart + bufused;
- }
- }
- if (i == -1) {
- perror("read");
- exit(1);
- }
+ buf = bufstart + bufused;
+ }
+ }
+ if (i == -1) {
+ perror("read");
+ exit(1);
+ }
- outfd = open(argv[1], O_CREAT | O_TRUNC | O_WRONLY,
- 0666);
- if (outfd == -1) {
- fprintf(stderr, "Can't open %s: %s\n", argv[1], strerror(errno));
- exit(1);
- }
+ outfd = open(argv[1], O_CREAT | O_TRUNC | O_WRONLY, 0666);
+ if (outfd == -1) {
+ fprintf(stderr, "Can't open %s: %s\n", argv[1], strerror(errno));
+ exit(1);
+ }
- i = write(outfd, bufstart, bufused);
- if (i == -1) {
- perror("write");
- exit(1);
- }
+ i = write(outfd, bufstart, bufused);
+ if (i == -1) {
+ perror("write");
+ exit(1);
+ }
- i = close(outfd);
- if (i == -1) {
- perror("close");
- exit(1);
- }
+ i = close(outfd);
+ if (i == -1) {
+ perror("close");
+ exit(1);
+ }
- return 0;
+ return 0;
}
<!--
-Copyright © 2006 Joey Hess
+Copyright © 2006 Joey Hess
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
<refentry>
- <refentryinfo>
- <author>
- <firstname>Joey</firstname>
- <surname>Hess</surname>
- </author>
- <date>2006-02-19</date>
- </refentryinfo>
+ <refentryinfo>
+ <author>
+ <firstname>Joey</firstname>
+ <surname>Hess</surname>
+ </author>
+ <date>2006-02-19</date>
+ </refentryinfo>
- <refmeta>
- <refentrytitle>sponge</refentrytitle>
- <manvolnum>1</manvolnum>
- </refmeta>
+ <refmeta>
+ <refentrytitle>sponge</refentrytitle>
+ <manvolnum>1</manvolnum>
+ </refmeta>
- <refnamediv>
- <refname>sponge</refname>
- <refpurpose>soak up standard input and write to a file</refpurpose>
- </refnamediv>
+ <refnamediv>
+ <refname>sponge</refname>
+ <refpurpose>soak up standard input and write to a file</refpurpose>
+ </refnamediv>
- <refsynopsisdiv>
- <cmdsynopsis>
- <command>sed '...' file | grep '...' | sponge file</command>
- </cmdsynopsis>
- </refsynopsisdiv>
+ <refsynopsisdiv>
+ <cmdsynopsis>
+ <command>sed '...' file | grep '...' | sponge file</command>
+ </cmdsynopsis>
+ </refsynopsisdiv>
- <refsect1>
- <title>DESCRIPTION</title>
-
- <para><command>sponge</command> reads standard input and writes it
- out to the specified file. Unlike a shell redirect, sponge soaks up
- all its input before opening the output file. This allows for
- constructing pipelines that read from and write to the same file.
- </para>
-
- </refsect1>
+ <refsect1>
+ <title>DESCRIPTION</title>
+
+ <para><command>sponge</command> reads standard input and
+ writes it out to the specified file. Unlike a shell
+ redirect, sponge soaks up all its input before
+ opening the output file. This allows for
+ constructing pipelines that read from and write to
+ the same file. </para>
+ </refsect1>
</refentry>