Simplify CRC table generation
[oweals/busybox.git] / libbb / libc5.c
1 /* vi: set sw=4 ts=4: */
2
3
4 #include <features.h>
5 #include <string.h>
6 #include <stdio.h>
7 #include <fcntl.h>
8 #include <paths.h>
9 #include <unistd.h>
10
11
12 #if __GNU_LIBRARY__ < 5
13
14
15 /* Copyright (C) 1991 Free Software Foundation, Inc.
16 This file is part of the GNU C Library.
17
18 The GNU C Library is free software; you can redistribute it and/or
19 modify it under the terms of the GNU Library General Public License as
20 published by the Free Software Foundation; either version 2 of the
21 License, or (at your option) any later version.
22
23 The GNU C Library is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26 Library General Public License for more details.
27
28 You should have received a copy of the GNU Library General Public
29 License along with the GNU C Library; see the file COPYING.LIB.  If
30 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
31 Cambridge, MA 02139, USA.  */
32
33 /*
34  * Modified by Manuel Novoa III     Mar 1, 2001
35  *
36  * Converted original strtok.c code of strtok to __strtok_r.
37  * Cleaned up logic and reduced code size.
38  */
39
40
41 char *strtok_r(char *s, const char *delim, char **save_ptr)
42 {
43         char *token;
44
45         token = 0;                                      /* Initialize to no token. */
46
47         if (s == 0) {                           /* If not first time called... */
48                 s = *save_ptr;                  /* restart from where we left off. */
49         }
50         
51         if (s != 0) {                           /* If not finished... */
52                 *save_ptr = 0;
53
54                 s += strspn(s, delim);  /* Skip past any leading delimiters. */
55                 if (*s != '\0') {               /* We have a token. */
56                         token = s;
57                         *save_ptr = strpbrk(token, delim); /* Find token's end. */
58                         if (*save_ptr != 0) {
59                                 /* Terminate the token and make SAVE_PTR point past it.  */
60                                 *(*save_ptr)++ = '\0';
61                         }
62                 }
63         }
64
65         return token;
66 }
67
68 /* Basically getdelim() with the delimiter hard wired to '\n' */
69 ssize_t getline(char **linebuf, size_t *n, FILE *file)
70 {
71       return (getdelim (linebuf, n, '\n', file));
72 }
73
74
75 /*
76  * daemon implementation for uClibc
77  *
78  * Copyright (c) 1991, 1993
79  *      The Regents of the University of California.  All rights reserved.
80  *
81  * Modified for uClibc by Erik Andersen 
82  *        <andersee@debian.org>, <andersen@lineo.com>
83  *
84  * The uClibc Library is free software; you can redistribute it and/or
85  * modify it under the terms of the GNU Library General Public License as
86  * published by the Free Software Foundation; either version 2 of the
87  * License, or (at your option) any later version.
88  * 
89  * The GNU C Library is distributed in the hope that it will be useful,
90  * but WITHOUT ANY WARRANTY; without even the implied warranty of
91  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
92  * Library General Public License for more details.
93  * 
94  * You should have received a copy of the GNU Library General Public
95  * License along with the GNU C Library; see the file COPYING.LIB.  If not,
96  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
97  * Boston, MA 02111-1307, USA. 
98  *
99  * Original copyright notice is retained at the end of this file.
100  */
101
102 int daemon( int nochdir, int noclose )
103 {
104     int fd;
105
106     switch (fork()) {
107         case -1:
108             return(-1);
109         case 0:
110             break;
111         default:
112             _exit(0);
113     }
114
115     if (setsid() == -1)
116         return(-1);
117
118     if (!nochdir)
119         chdir("/");
120
121     if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
122         dup2(fd, STDIN_FILENO);
123         dup2(fd, STDOUT_FILENO);
124         dup2(fd, STDERR_FILENO);
125         if (fd > 2)
126             close(fd);
127     }
128     return(0);
129 }
130
131
132 /*-
133  * Copyright (c) 1990, 1993
134  *      The Regents of the University of California.  All rights reserved.
135  *
136  * Redistribution and use in source and binary forms, with or without
137  * modification, are permitted provided that the following conditions
138  * are met:
139  * 1. Redistributions of source code must retain the above copyright
140  *    notice, this list of conditions and the following disclaimer.
141  * 2. Redistributions in binary form must reproduce the above copyright
142  *    notice, this list of conditions and the following disclaimer in the
143  *    documentation and/or other materials provided with the distribution.
144  *
145  * 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change 
146  *              ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change> 
147  *
148  * 4. Neither the name of the University nor the names of its contributors
149  *    may be used to endorse or promote products derived from this software
150  *    without specific prior written permission.
151  *
152  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
153  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
154  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
155  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
156  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
157  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
158  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
159  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
160  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
161  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
162  * SUCH DAMAGE.
163  */
164
165
166 #endif  
167