From 166cc47deaa1da2477806e3bb9a1c6bd0b94ff52 Mon Sep 17 00:00:00 2001 From: joseph Date: Wed, 7 Mar 2012 19:31:25 +0000 Subject: Merge changes between r17384 and r17457 from /fsf/trunk. git-svn-id: svn://svn.eglibc.org/trunk@17458 7b3dc134-2b1b-0410-93df-9e9f96275f8d --- libc/manual/examples/README | 8 ++++++++ libc/manual/examples/add.c | 17 +++++++++++++++++ libc/manual/examples/argp-ex1.c | 17 ++++++++++++++++- libc/manual/examples/argp-ex2.c | 17 ++++++++++++++++- libc/manual/examples/argp-ex3.c | 17 ++++++++++++++++- libc/manual/examples/argp-ex4.c | 17 ++++++++++++++++- libc/manual/examples/atexit.c | 19 ++++++++++++++++++- libc/manual/examples/db.c | 17 +++++++++++++++++ libc/manual/examples/dir.c | 17 +++++++++++++++++ libc/manual/examples/dir2.c | 17 +++++++++++++++++ libc/manual/examples/execinfo.c | 17 +++++++++++++++++ libc/manual/examples/filecli.c | 17 +++++++++++++++++ libc/manual/examples/filesrv.c | 17 +++++++++++++++++ libc/manual/examples/fmtmsgexpl.c | 17 +++++++++++++++++ libc/manual/examples/genpass.c | 31 ++++++++++++++++++++++++------- libc/manual/examples/inetcli.c | 19 ++++++++++++++++++- libc/manual/examples/inetsrv.c | 17 +++++++++++++++++ libc/manual/examples/isockad.c | 21 +++++++++++++++++++-- libc/manual/examples/longopt.c | 17 +++++++++++++++++ libc/manual/examples/memopen.c | 17 +++++++++++++++++ libc/manual/examples/memstrm.c | 17 +++++++++++++++++ libc/manual/examples/mkfsock.c | 17 +++++++++++++++++ libc/manual/examples/mkisock.c | 19 ++++++++++++++++++- libc/manual/examples/mygetpass.c | 21 +++++++++++++++++++-- libc/manual/examples/pipe.c | 17 +++++++++++++++++ libc/manual/examples/popen.c | 17 +++++++++++++++++ libc/manual/examples/rprintf.c | 17 +++++++++++++++++ libc/manual/examples/search.c | 23 ++++++++++++++++++++--- libc/manual/examples/select.c | 17 +++++++++++++++++ libc/manual/examples/setjmp.c | 21 +++++++++++++++++++-- libc/manual/examples/sigh1.c | 21 +++++++++++++++++++-- libc/manual/examples/sigusr.c | 21 +++++++++++++++++++-- libc/manual/examples/stpcpy.c | 17 +++++++++++++++++ libc/manual/examples/strdupa.c | 17 +++++++++++++++++ libc/manual/examples/strftim.c | 17 +++++++++++++++++ libc/manual/examples/strncat.c | 17 +++++++++++++++++ libc/manual/examples/subopt.c | 17 +++++++++++++++++ libc/manual/examples/swapcontext.c | 17 +++++++++++++++++ libc/manual/examples/termios.c | 21 +++++++++++++++++++-- libc/manual/examples/testopt.c | 17 +++++++++++++++++ libc/manual/examples/testpass.c | 21 +++++++++++++++++++-- libc/manual/examples/timeval_subtract.c | 17 +++++++++++++++++ 42 files changed, 728 insertions(+), 31 deletions(-) create mode 100644 libc/manual/examples/README (limited to 'libc/manual/examples') diff --git a/libc/manual/examples/README b/libc/manual/examples/README new file mode 100644 index 000000000..7d0070fdd --- /dev/null +++ b/libc/manual/examples/README @@ -0,0 +1,8 @@ +These are source files for example code that appears in The GNU C +Library Reference Manual. + +While the manual itself is licensed under the terms of the GNU Free +Documentation License, you can use these source files on their own +under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License, or (at your +option) any later version. diff --git a/libc/manual/examples/add.c b/libc/manual/examples/add.c index e4b1bba36..d4b9af9c9 100644 --- a/libc/manual/examples/add.c +++ b/libc/manual/examples/add.c @@ -1,3 +1,20 @@ +/* Example of a Variadic Function + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include #include diff --git a/libc/manual/examples/argp-ex1.c b/libc/manual/examples/argp-ex1.c index 931a8264a..01c363921 100644 --- a/libc/manual/examples/argp-ex1.c +++ b/libc/manual/examples/argp-ex1.c @@ -1,4 +1,19 @@ -/* Argp example #1 -- a minimal program using argp */ +/* Argp example #1 -- a minimal program using argp + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ /* This is (probably) the smallest possible program that uses argp. It won't do much except give an error diff --git a/libc/manual/examples/argp-ex2.c b/libc/manual/examples/argp-ex2.c index 097ce7622..0e038bbc9 100644 --- a/libc/manual/examples/argp-ex2.c +++ b/libc/manual/examples/argp-ex2.c @@ -1,4 +1,19 @@ -/* Argp example #2 -- a pretty minimal program using argp */ +/* Argp example #2 -- a pretty minimal program using argp + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ /* This program doesn't use any options or arguments, but uses argp to be compliant with the GNU standard command line diff --git a/libc/manual/examples/argp-ex3.c b/libc/manual/examples/argp-ex3.c index d5896ee13..689d7cfda 100644 --- a/libc/manual/examples/argp-ex3.c +++ b/libc/manual/examples/argp-ex3.c @@ -1,4 +1,19 @@ -/* Argp example #3 -- a program with options and arguments using argp */ +/* Argp example #3 -- a program with options and arguments using argp + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ /* This program uses the same features as example 2, and uses options and arguments. diff --git a/libc/manual/examples/argp-ex4.c b/libc/manual/examples/argp-ex4.c index 2b61358c7..b946dd106 100644 --- a/libc/manual/examples/argp-ex4.c +++ b/libc/manual/examples/argp-ex4.c @@ -1,4 +1,19 @@ -/* Argp example #4 -- a program with somewhat more complicated options */ +/* Argp example #4 -- a program with somewhat more complicated options + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ /* This program uses the same features as example 3, but has more options, and somewhat more structure in the -help output. It diff --git a/libc/manual/examples/atexit.c b/libc/manual/examples/atexit.c index 42bba7112..5f07c8751 100644 --- a/libc/manual/examples/atexit.c +++ b/libc/manual/examples/atexit.c @@ -1,7 +1,24 @@ +/* Cleanups on Exit + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include #include -void +void bye (void) { puts ("Goodbye, cruel world...."); diff --git a/libc/manual/examples/db.c b/libc/manual/examples/db.c index 1a1cb0c0d..d6405e50d 100644 --- a/libc/manual/examples/db.c +++ b/libc/manual/examples/db.c @@ -1,3 +1,20 @@ +/* User and Group Database Example + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include #include #include diff --git a/libc/manual/examples/dir.c b/libc/manual/examples/dir.c index 8ab77dc34..9ca63fec0 100644 --- a/libc/manual/examples/dir.c +++ b/libc/manual/examples/dir.c @@ -1,3 +1,20 @@ +/* Simple Program to List a Directory + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + /*@group*/ #include #include diff --git a/libc/manual/examples/dir2.c b/libc/manual/examples/dir2.c index a75c88574..7f095c84d 100644 --- a/libc/manual/examples/dir2.c +++ b/libc/manual/examples/dir2.c @@ -1,3 +1,20 @@ +/* Simple Program to List a Directory, Mark II + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + /*@group*/ #include #include diff --git a/libc/manual/examples/execinfo.c b/libc/manual/examples/execinfo.c index 5a0490195..18a3a2973 100644 --- a/libc/manual/examples/execinfo.c +++ b/libc/manual/examples/execinfo.c @@ -1,3 +1,20 @@ +/* Obtain a backtrace and print it. + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include #include #include diff --git a/libc/manual/examples/filecli.c b/libc/manual/examples/filecli.c index 9f64445fa..71dc46180 100644 --- a/libc/manual/examples/filecli.c +++ b/libc/manual/examples/filecli.c @@ -1,3 +1,20 @@ +/* Example of Reading Datagrams + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include #include #include diff --git a/libc/manual/examples/filesrv.c b/libc/manual/examples/filesrv.c index 32507c655..e1f80aa7b 100644 --- a/libc/manual/examples/filesrv.c +++ b/libc/manual/examples/filesrv.c @@ -1,3 +1,20 @@ +/* Datagram Socket Example + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include #include #include diff --git a/libc/manual/examples/fmtmsgexpl.c b/libc/manual/examples/fmtmsgexpl.c index 42b8bb517..fd7b16bb2 100644 --- a/libc/manual/examples/fmtmsgexpl.c +++ b/libc/manual/examples/fmtmsgexpl.c @@ -1,3 +1,20 @@ +/* How to use fmtmsg and addseverity. + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include int diff --git a/libc/manual/examples/genpass.c b/libc/manual/examples/genpass.c index a7626dbed..cb4d99f06 100644 --- a/libc/manual/examples/genpass.c +++ b/libc/manual/examples/genpass.c @@ -1,31 +1,48 @@ +/* Encrypting Passwords + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include #include #include #include -int +int main(void) { unsigned long seed[2]; char salt[] = "$1$........"; - const char *const seedchars = + const char *const seedchars = "./0123456789ABCDEFGHIJKLMNOPQRST" "UVWXYZabcdefghijklmnopqrstuvwxyz"; char *password; int i; - - /* Generate a (not very) random seed. + + /* Generate a (not very) random seed. You should do it better than this... */ seed[0] = time(NULL); seed[1] = getpid() ^ (seed[0] >> 14 & 0x30000); - + /* Turn it into printable characters from `seedchars'. */ for (i = 0; i < 8; i++) salt[3+i] = seedchars[(seed[i/5] >> (i%5)*6) & 0x3f]; - + /* Read in the user's password and encrypt it. */ password = crypt(getpass("Password:"), salt); - + /* Print the results. */ puts(password); return 0; diff --git a/libc/manual/examples/inetcli.c b/libc/manual/examples/inetcli.c index 35dfb379e..afd4a91a6 100644 --- a/libc/manual/examples/inetcli.c +++ b/libc/manual/examples/inetcli.c @@ -1,3 +1,20 @@ +/* Byte Stream Socket Example + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include #include #include @@ -11,7 +28,7 @@ #define MESSAGE "Yow!!! Are we having fun yet?!?" #define SERVERHOST "mescaline.gnu.org" -void +void write_to_server (int filedes) { int nbytes; diff --git a/libc/manual/examples/inetsrv.c b/libc/manual/examples/inetsrv.c index 3d544c005..d245f0d11 100644 --- a/libc/manual/examples/inetsrv.c +++ b/libc/manual/examples/inetsrv.c @@ -1,3 +1,20 @@ +/* Byte Stream Connection Server Example + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include #include #include diff --git a/libc/manual/examples/isockad.c b/libc/manual/examples/isockad.c index 9c21149a8..b7c73a7f4 100644 --- a/libc/manual/examples/isockad.c +++ b/libc/manual/examples/isockad.c @@ -1,10 +1,27 @@ +/* Internet Socket Example using sockaddr_in. + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include #include #include #include #include -void +void init_sockaddr (struct sockaddr_in *name, const char *hostname, uint16_t port) @@ -14,7 +31,7 @@ init_sockaddr (struct sockaddr_in *name, name->sin_family = AF_INET; name->sin_port = htons (port); hostinfo = gethostbyname (hostname); - if (hostinfo == NULL) + if (hostinfo == NULL) { fprintf (stderr, "Unknown host %s.\n", hostname); exit (EXIT_FAILURE); diff --git a/libc/manual/examples/longopt.c b/libc/manual/examples/longopt.c index 989e88713..6e7d4d939 100644 --- a/libc/manual/examples/longopt.c +++ b/libc/manual/examples/longopt.c @@ -1,3 +1,20 @@ +/* Example of Parsing Long Options with getopt_long. + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include #include #include diff --git a/libc/manual/examples/memopen.c b/libc/manual/examples/memopen.c index 682830fe5..3fa29d521 100644 --- a/libc/manual/examples/memopen.c +++ b/libc/manual/examples/memopen.c @@ -1,3 +1,20 @@ +/* String Streams + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include static char buffer[] = "foobar"; diff --git a/libc/manual/examples/memstrm.c b/libc/manual/examples/memstrm.c index 1674c36e0..be8366064 100644 --- a/libc/manual/examples/memstrm.c +++ b/libc/manual/examples/memstrm.c @@ -1,3 +1,20 @@ +/* open_memstream example. + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include int diff --git a/libc/manual/examples/mkfsock.c b/libc/manual/examples/mkfsock.c index 615ecd868..e5c3b2847 100644 --- a/libc/manual/examples/mkfsock.c +++ b/libc/manual/examples/mkfsock.c @@ -1,3 +1,20 @@ +/* Example of Local-Namespace Sockets + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include #include #include diff --git a/libc/manual/examples/mkisock.c b/libc/manual/examples/mkisock.c index 2fd8b3d2f..68cf348f1 100644 --- a/libc/manual/examples/mkisock.c +++ b/libc/manual/examples/mkisock.c @@ -1,9 +1,26 @@ +/* Internet Socket Example + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include #include #include #include -int +int make_socket (uint16_t port) { int sock; diff --git a/libc/manual/examples/mygetpass.c b/libc/manual/examples/mygetpass.c index 6fe06f463..a927a13ac 100644 --- a/libc/manual/examples/mygetpass.c +++ b/libc/manual/examples/mygetpass.c @@ -1,3 +1,20 @@ +/* Reading Passwords + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include #include @@ -14,12 +31,12 @@ my_getpass (char **lineptr, size_t *n, FILE *stream) new.c_lflag &= ~ECHO; if (tcsetattr (fileno (stream), TCSAFLUSH, &new) != 0) return -1; - + /* Read the password. */ nread = getline (lineptr, n, stream); /* Restore terminal. */ (void) tcsetattr (fileno (stream), TCSAFLUSH, &old); - + return nread; } diff --git a/libc/manual/examples/pipe.c b/libc/manual/examples/pipe.c index 92d339a7b..b03c90f8f 100644 --- a/libc/manual/examples/pipe.c +++ b/libc/manual/examples/pipe.c @@ -1,3 +1,20 @@ +/* Creating a Pipe + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include #include #include diff --git a/libc/manual/examples/popen.c b/libc/manual/examples/popen.c index 1b9ee826b..6716dc246 100644 --- a/libc/manual/examples/popen.c +++ b/libc/manual/examples/popen.c @@ -1,3 +1,20 @@ +/* Pipe to a Subprocess + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include #include diff --git a/libc/manual/examples/rprintf.c b/libc/manual/examples/rprintf.c index 2b8f6bfe7..14de9d243 100644 --- a/libc/manual/examples/rprintf.c +++ b/libc/manual/examples/rprintf.c @@ -1,3 +1,20 @@ +/* Printf Extension Example + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include #include #include diff --git a/libc/manual/examples/search.c b/libc/manual/examples/search.c index 182e6e4a3..e37656721 100644 --- a/libc/manual/examples/search.c +++ b/libc/manual/examples/search.c @@ -1,3 +1,20 @@ +/* Searching and Sorting Example + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include #include #include @@ -35,7 +52,7 @@ int count = sizeof (muppets) / sizeof (struct critter); /* This is the comparison function used for sorting and searching. */ -int +int critter_cmp (const struct critter *c1, const struct critter *c2) { return strcmp (c1->name, c2->name); @@ -44,7 +61,7 @@ critter_cmp (const struct critter *c1, const struct critter *c2) /* Print information about a critter. */ -void +void print_critter (const struct critter *c) { printf ("%s, the %s\n", c->name, c->species); @@ -54,7 +71,7 @@ print_critter (const struct critter *c) /*@group*/ /* Do the lookup into the sorted array. */ -void +void find_critter (const char *name) { struct critter target, *result; diff --git a/libc/manual/examples/select.c b/libc/manual/examples/select.c index a65ed7750..635163026 100644 --- a/libc/manual/examples/select.c +++ b/libc/manual/examples/select.c @@ -1,3 +1,20 @@ +/* Waiting for Input or Output + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + /*@group*/ #include #include diff --git a/libc/manual/examples/setjmp.c b/libc/manual/examples/setjmp.c index 023339c60..ffd7744c1 100644 --- a/libc/manual/examples/setjmp.c +++ b/libc/manual/examples/setjmp.c @@ -1,10 +1,27 @@ +/* Introduction to Non-Local Exits + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include #include #include jmp_buf main_loop; -void +void abort_to_main_loop (int status) { longjmp (main_loop, status); @@ -21,7 +38,7 @@ main (void) } -void +void do_command (void) { char buffer[128]; diff --git a/libc/manual/examples/sigh1.c b/libc/manual/examples/sigh1.c index 2c6e95b9c..d05afd9af 100644 --- a/libc/manual/examples/sigh1.c +++ b/libc/manual/examples/sigh1.c @@ -1,3 +1,20 @@ +/* Signal Handlers that Return + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include #include #include @@ -6,14 +23,14 @@ volatile sig_atomic_t keep_going = 1; /* The signal handler just clears the flag and re-enables itself. */ -void +void catch_alarm (int sig) { keep_going = 0; signal (sig, catch_alarm); } -void +void do_stuff (void) { puts ("Doing stuff while waiting for alarm...."); diff --git a/libc/manual/examples/sigusr.c b/libc/manual/examples/sigusr.c index 11e3ceee8..5bfbc8071 100644 --- a/libc/manual/examples/sigusr.c +++ b/libc/manual/examples/sigusr.c @@ -1,3 +1,20 @@ +/* Using kill for Communication + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + /*@group*/ #include #include @@ -8,14 +25,14 @@ /* When a @code{SIGUSR1} signal arrives, set this variable. */ volatile sig_atomic_t usr_interrupt = 0; -void +void synch_signal (int sig) { usr_interrupt = 1; } /* The child process executes this function. */ -void +void child_function (void) { /* Perform initialization. */ diff --git a/libc/manual/examples/stpcpy.c b/libc/manual/examples/stpcpy.c index b83226354..f94cb636b 100644 --- a/libc/manual/examples/stpcpy.c +++ b/libc/manual/examples/stpcpy.c @@ -1,3 +1,20 @@ +/* stpcpy example. + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include #include diff --git a/libc/manual/examples/strdupa.c b/libc/manual/examples/strdupa.c index 7d6ef3994..f01e11524 100644 --- a/libc/manual/examples/strdupa.c +++ b/libc/manual/examples/strdupa.c @@ -1,3 +1,20 @@ +/* strdupa example. + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include #include #include diff --git a/libc/manual/examples/strftim.c b/libc/manual/examples/strftim.c index 7f95ef02a..93428177e 100644 --- a/libc/manual/examples/strftim.c +++ b/libc/manual/examples/strftim.c @@ -1,3 +1,20 @@ +/* Time Functions Example + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include #include diff --git a/libc/manual/examples/strncat.c b/libc/manual/examples/strncat.c index 948d662a4..fb7b7078a 100644 --- a/libc/manual/examples/strncat.c +++ b/libc/manual/examples/strncat.c @@ -1,3 +1,20 @@ +/* strncat example. + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include #include diff --git a/libc/manual/examples/subopt.c b/libc/manual/examples/subopt.c index a87bee166..ecf75f9a9 100644 --- a/libc/manual/examples/subopt.c +++ b/libc/manual/examples/subopt.c @@ -1,3 +1,20 @@ +/* Parsing of Suboptions Example + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include #include #include diff --git a/libc/manual/examples/swapcontext.c b/libc/manual/examples/swapcontext.c index f733510f8..c993d1450 100644 --- a/libc/manual/examples/swapcontext.c +++ b/libc/manual/examples/swapcontext.c @@ -1,3 +1,20 @@ +/* Complete Context Control + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include #include #include diff --git a/libc/manual/examples/termios.c b/libc/manual/examples/termios.c index 6db5990a0..40d4325b5 100644 --- a/libc/manual/examples/termios.c +++ b/libc/manual/examples/termios.c @@ -1,3 +1,20 @@ +/* Noncanonical Mode Example + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include #include #include @@ -7,13 +24,13 @@ struct termios saved_attributes; -void +void reset_input_mode (void) { tcsetattr (STDIN_FILENO, TCSANOW, &saved_attributes); } -void +void set_input_mode (void) { struct termios tattr; diff --git a/libc/manual/examples/testopt.c b/libc/manual/examples/testopt.c index 44ca8e4ad..081742d85 100644 --- a/libc/manual/examples/testopt.c +++ b/libc/manual/examples/testopt.c @@ -1,3 +1,20 @@ +/* Example of Parsing Arguments with getopt. + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + /*@group*/ #include #include diff --git a/libc/manual/examples/testpass.c b/libc/manual/examples/testpass.c index 5bd616d2a..4e05a9059 100644 --- a/libc/manual/examples/testpass.c +++ b/libc/manual/examples/testpass.c @@ -1,9 +1,26 @@ +/* Verify a password. + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + #include #include #include #include -int +int main(void) { /* Hashed form of "GNU libc manual". */ @@ -11,7 +28,7 @@ main(void) char *result; int ok; - + /*@group*/ /* Read in the user's password and encrypt it, passing the expected password in as the salt. */ diff --git a/libc/manual/examples/timeval_subtract.c b/libc/manual/examples/timeval_subtract.c index 683322ffe..f0f237568 100644 --- a/libc/manual/examples/timeval_subtract.c +++ b/libc/manual/examples/timeval_subtract.c @@ -1,3 +1,20 @@ +/* struct timeval subtraction. + Copyright (C) 1991-2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, if not, see . +*/ + /* Subtract the `struct timeval' values X and Y, storing the result in RESULT. Return 1 if the difference is negative, otherwise 0. */ -- cgit v1.2.3