diff options
-rw-r--r-- | libshouldbeinlibc/=argz.c | 190 | ||||
-rw-r--r-- | libshouldbeinlibc/=argz.h | 89 | ||||
-rw-r--r-- | libshouldbeinlibc/=envz.c | 171 | ||||
-rw-r--r-- | libshouldbeinlibc/=envz.h | 55 | ||||
-rw-r--r-- | libshouldbeinlibc/=line.c | 147 | ||||
-rw-r--r-- | libshouldbeinlibc/=line.h | 128 | ||||
-rw-r--r-- | libshouldbeinlibc/=path-lookup.c | 120 |
7 files changed, 0 insertions, 900 deletions
diff --git a/libshouldbeinlibc/=argz.c b/libshouldbeinlibc/=argz.c deleted file mode 100644 index fd90a1e2..00000000 --- a/libshouldbeinlibc/=argz.c +++ /dev/null @@ -1,190 +0,0 @@ -/* Routines for dealing with '\0' separated arg vectors. - - Copyright (C) 1995 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> - - 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, 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, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include <stdlib.h> -#include <string.h> -#include <errno.h> - -/* ---------------------------------------------------------------- */ - -/* Make a '\0' separated arg vector from a unix argv vector, returning it in - ARGZ, and the total length in LEN. If a memory allocation error occurs, - ENOMEM is returned, otherwise 0. */ -error_t -argz_create(char **argv, char **argz, int *len) -{ - int tlen = 0; - char **argp; - - for (argp = argv; *argp != NULL; argp++) - tlen += strlen(*argp) + 1; - - *len = tlen; - - if (tlen == 0) - *argz = NULL; - else - { - *argz = malloc(tlen); - if (*argz == NULL) - return ENOMEM; - - while (tlen > 0) - { - tlen -= strlen(*--argp) + 1; - strcpy(*argz + tlen, *argp); - } - } - - return 0; -} - -/* ---------------------------------------------------------------- */ - -/* Returns the number of strings in ARGZ. */ -int -argz_count (char *argz, int len) -{ - int count = 0; - while (len > 0) - { - int part_len = strlen(argz); - argz += part_len + 1; - len -= part_len + 1; - count++; - } - return count; -} - -/* ---------------------------------------------------------------- */ - -/* Puts pointers to each string in ARGZ into ARGV, which must be large enough - to hold them all. */ -void -argz_extract (char *argz, int len, char **argv) -{ - while (len > 0) - { - int part_len = strlen(argz); - *argv++ = argz; - argz += part_len + 1; - len -= part_len + 1; - } -} - -/* ---------------------------------------------------------------- */ - -/* Make '\0' separated arg vector ARGZ printable by converting all the '\0's - except the last into the character SEP. */ -void -argz_stringify(char *argz, int len, int sep) -{ - while (len > 0) - { - int part_len = strlen(argz); - argz += part_len; - len -= part_len + 1; - if (len > 0) - *argz++ = sep; - } -} - -/* Add BUF, of length BUF_LEN to the argz vector in ARGZ & ARGZ_LEN. */ -error_t -argz_append (char **argz, unsigned *argz_len, char *buf, unsigned buf_len) -{ - unsigned new_argz_len = *argz_len + buf_len; - char *new_argz = realloc (*argz, new_argz_len); - if (new_argz) - { - bcopy (buf, new_argz + *argz_len, buf_len); - *argz = new_argz; - *argz_len = new_argz_len; - return 0; - } - else - return ENOMEM; -} - -/* Add STR to the argz vector in ARGZ & ARGZ_LEN. This should be moved into - argz.c in libshouldbelibc. */ -error_t -argz_add (char **argz, unsigned *argz_len, char *str) -{ - return argz_append (argz, argz_len, str, strlen (str) + 1); -} - -/* Delete ENTRY from ARGZ & ARGZ_LEN, if any. */ -void -argz_delete (char **argz, unsigned *argz_len, char *entry) -{ - if (entry) - /* Get rid of the old value for NAME. */ - { - unsigned entry_len = strlen (entry) + 1; - *argz_len -= entry_len; - bcopy (entry + entry_len, entry, *argz_len - (entry - *argz)); - if (*argz_len == 0) - { - free (*argz); - *argz = 0; - } - } -} - -/* Insert ENTRY into ARGZ & ARGZ_LEN before BEFORE, which should be an - existing entry in ARGZ; if BEFORE is NULL, ENTRY is appended to the end. - Since ARGZ's first entry is the same as ARGZ, argz_insert (ARGZ, ARGZ_LEN, - ARGZ, ENTRY) will insert ENTRY at the beginning of ARGZ. If BEFORE is not - in ARGZ, EINVAL is returned, else if memory can't be allocated for the new - ARGZ, ENOMEM is returned, else 0. */ -error_t -argz_insert (char **argz, unsigned *argz_len, char *before, char *entry) -{ - if (! before) - return argz_add (argz, argz_len, entry); - - if (before < *argz || before >= *argz + *argz_len) - return EINVAL; - - if (before > *argz) - /* Make sure before is actually the beginning of an entry. */ - while (before[-1]) - before--; - - { - unsigned after_before = *argz_len - (before - *argz); - unsigned entry_len = strlen (entry) + 1; - unsigned new_argz_len = *argz_len + entry_len; - char *new_argz = realloc (*argz, new_argz_len); - - if (new_argz) - { - before = new_argz + (before - *argz); - bcopy (before, before + entry_len, after_before); - bcopy (entry, before, entry_len); - *argz = new_argz; - *argz_len = new_argz_len; - return 0; - } - else - return ENOMEM; - } -} diff --git a/libshouldbeinlibc/=argz.h b/libshouldbeinlibc/=argz.h deleted file mode 100644 index 1de0cd64..00000000 --- a/libshouldbeinlibc/=argz.h +++ /dev/null @@ -1,89 +0,0 @@ -/* Routines for dealing with '\0' separated arg vectors. - - Copyright (C) 1995 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> - - 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, 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, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#ifndef __ARGZ_H__ -#define __ARGZ_H__ - -/* Make a '\0' separated arg vector from a unix argv vector, returning it in - ARGZ, and the total length in LEN. If a memory allocation error occurs, - ENOMEM is returned, otherwise 0. The result can be destroyed using free. */ -error_t argz_create(char **argv, char **argz, int *len); - -/* Returns the number of strings in ARGZ. */ -int argz_count (char *argz, int len); - -/* Puts pointers to each string in ARGZ into ARGV, which must be large enough - to hold them all. */ -void argz_extract (char *argz, int len, char **argv); - -/* Make '\0' separated arg vector ARGZ printable by converting all the '\0's - except the last into the character SEP. */ -void argz_stringify(char *argz, int len, int sep); - -/* Add BUF, of length BUF_LEN to the argz vector in ARGZ & ARGZ_LEN. */ -error_t -argz_append (char **argz, unsigned *argz_len, char *buf, unsigned buf_len); - -/* Add STR to the argz vector in ARGZ & ARGZ_LEN. This should be moved into - argz.c in libshouldbelibc. */ -error_t argz_add (char **argz, unsigned *argz_len, char *str); - -/* Delete ENTRY from ARGZ & ARGZ_LEN, if any. */ -void argz_delete (char **argz, unsigned *argz_len, char *entry); - -/* Insert ENTRY into ARGZ & ARGZ_LEN before BEFORE, which should be an - existing entry in ARGZ; if BEFORE is NULL, ENTRY is appended to the end. - Since ARGZ's first entry is the same as ARGZ, argz_insert (ARGZ, ARGZ_LEN, - ARGZ, ENTRY) will insert ENTRY at the beginning of ARGZ. If BEFORE is not - in ARGZ, EINVAL is returned, else if memory can't be allocated for the new - ARGZ, ENOMEM is returned, else 0. */ -error_t -argz_insert (char **argz, unsigned *argz_len, char *before, char *entry); - -/* Returns the next entry in ARGZ & ARGZ_LEN after ENTRY, or NULL if there - are no more. If entry is NULL, then the first entry is returned. This - behavior allows two convenient iteration styles: - - char *entry = 0; - while (entry = argz_next (argz, argz_len, entry)) - ...; - - or - - char *entry; - for (entry = argz; entry; entry = argz_next (argz, argz_len, entry)) - ...; -*/ -extern inline char * -argz_next (char *argz, unsigned argz_len, char *entry) -{ - if (entry) - if (entry >= argz + argz_len) - return 0; - else - return entry + strlen (entry) + 1; - else - if (argz_len > 0) - return argz; - else - return 0; -} - -#endif /* __ARGZ_H__ */ diff --git a/libshouldbeinlibc/=envz.c b/libshouldbeinlibc/=envz.c deleted file mode 100644 index 4d0816e4..00000000 --- a/libshouldbeinlibc/=envz.c +++ /dev/null @@ -1,171 +0,0 @@ -/* Routines for dealing with '\0' separated environment vectors - - Copyright (C) 1995, 1996 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> - - 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, 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, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include <malloc.h> -#include <string.h> - -#include "envz.h" - -/* The character separating names from values in an envz. */ -#define SEP '=' - -/* Returns a pointer to the entry in ENVZ for NAME, or 0 if there is none. - If NAME contains the separator character, only the portion before it is - used in the comparison. */ -char * -envz_entry (char *envz, unsigned envz_len, char *name) -{ - while (envz_len) - { - char *p = name; - char *entry = envz; /* Start of this entry. */ - - /* See how far NAME and ENTRY match. */ - while (envz_len && *p == *envz && *p && *p != SEP) - p++, envz++, envz_len--; - - if ((*envz == '\0' || *envz == SEP) && (*p == '\0' || *p == SEP)) - /* Bingo! */ - return entry; - - /* No match, skip to the next entry. */ - while (envz_len && *envz) - envz++, envz_len--; - if (envz_len) - envz++, envz_len--; /* skip '\0' */ - } - - return 0; -} - -/* Returns a pointer to the value portion of the entry in ENVZ for NAME, or 0 - if there is none. */ -char * -envz_get (char *envz, unsigned envz_len, char *name) -{ - char *entry = envz_entry (envz, envz_len, name); - if (entry) - { - while (*entry && *entry != SEP) - entry++; - if (*entry) - entry++; - else - entry = 0; /* A null entry. */ - } - return entry; -} - -/* Remove the entry for NAME from ENVZ & ENVZ_LEN, if any. */ -void -envz_remove (char **envz, unsigned *envz_len, char *name) -{ - char *entry = envz_entry (*envz, *envz_len, name); - if (entry) - argz_delete (envz, envz_len, entry); -} - -/* Adds an entry for NAME with value VALUE to ENVZ & ENVZ_LEN. If an entry - with the same name already exists in ENVZ, it is removed. If VALUE is - NULL, then the new entry will a special null one, for which envz_get will - return NULL, although envz_entry will still return an entry; this is handy - because when merging with another envz, the null entry can override an - entry in the other one. Null entries can be removed with envz_strip (). */ -error_t -envz_add (char **envz, unsigned *envz_len, char *name, char *value) -{ - envz_remove (envz, envz_len, name); - - if (value) - /* Add the new value, if there is one. */ - { - unsigned name_len = strlen (name); - unsigned value_len = strlen (value); - unsigned old_envz_len = *envz_len; - unsigned new_envz_len = old_envz_len + name_len + 1 + value_len + 1; - char *new_envz = realloc (*envz, new_envz_len); - - if (new_envz) - { - bcopy (name, new_envz + old_envz_len, name_len); - new_envz[old_envz_len + name_len] = SEP; - bcopy (value, new_envz + old_envz_len + name_len + 1, value_len); - new_envz[new_envz_len - 1] = 0; - - *envz = new_envz; - *envz_len = new_envz_len; - - return 0; - } - else - return ENOMEM; - } - else - /* Add a null entry. */ - return argz_add (envz, envz_len, name); -} - -/* Adds each entry in ENVZ2 to ENVZ & ENVZ_LEN, as if with envz_add(). If - OVERRIDE is true, then values in ENVZ2 will supercede those with the same - name in ENV, otherwise not. */ -error_t -envz_merge (char **envz, unsigned *envz_len, char *envz2, unsigned envz2_len, - int override) -{ - error_t err = 0; - - while (envz2_len && ! err) - { - char *old = envz_entry (*envz, *envz_len, envz2); - size_t new_len = strlen (envz2) + 1; - - if (! old) - err = argz_append (envz, envz_len, envz2, new_len); - else if (override) - { - argz_delete (envz, envz_len, old); - err = argz_append (envz, envz_len, envz2, new_len); - } - - envz2 += new_len; - envz2_len -= new_len; - } - - return err; -} - -/* Remove null entries. */ -void -envz_strip (char **envz, unsigned *envz_len) -{ - char *entry = *envz; - unsigned left = *envz_len; - while (left) - { - unsigned entry_len = strlen (entry) + 1; - left -= entry_len; - if (! index (entry, SEP)) - /* Null entry. */ - bcopy (entry, entry + entry_len, left); - else - entry += entry_len; - } - *envz_len = entry - *envz; -} diff --git a/libshouldbeinlibc/=envz.h b/libshouldbeinlibc/=envz.h deleted file mode 100644 index 55224c72..00000000 --- a/libshouldbeinlibc/=envz.h +++ /dev/null @@ -1,55 +0,0 @@ -/* Routines for dealing with '\0' separated environment vectors - - Copyright (C) 1995 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> - - 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, 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, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#ifndef __ENVZ_H__ -#define __ENVZ_H__ - -#include <errno.h> - -/* Envz's are argz's too, and should be created etc., using the same - routines. */ -#include <argz.h> - -/* Returns a pointer to the entry in ENVZ for NAME, or 0 if there is none. */ -char *envz_entry (char *envz, unsigned envz_len, char *name); - -/* Returns a pointer to the value portion of the entry in ENVZ for NAME, or 0 - if there is none. */ -char *envz_get (char *envz, unsigned envz_len, char *name); - -/* Adds an entry for NAME with value VALUE to ENVZ & ENVZ_LEN. If an entry - with the same name already exists in ENVZ, it is removed. If VALUE is - NULL, then the new entry will a special null one, for which envz_get will - return NULL, although envz_entry will still return an entry; this is handy - because when merging with another envz, the null entry can override an - entry in the other one. Null entries can be removed with envz_strip (). */ -error_t envz_add (char **envz, unsigned *envz_len, char *name, char *value); - -/* Adds each entry in ENVZ2 to ENVZ & ENVZ_LEN, as if with envz_add(). If - OVERRIDE is true, then values in ENVZ2 will supercede those with the same - name in ENV, otherwise not. */ -error_t -envz_merge (char **envz, unsigned *envz_len, char *envz2, unsigned envz2_len, - int override); - -/* Remove null entries. */ -void envz_strip (char **envz, unsigned *envz_len); - -#endif /* __ENVZ_H__ */ diff --git a/libshouldbeinlibc/=line.c b/libshouldbeinlibc/=line.c deleted file mode 100644 index 1c8eab8e..00000000 --- a/libshouldbeinlibc/=line.c +++ /dev/null @@ -1,147 +0,0 @@ -/* Simple output formatting functions - - Copyright (C) 1995, 1996 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> - - This file is part of the GNU Hurd. - - The GNU Hurd 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, or (at - your option) any later version. - - The GNU Hurd 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, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include <malloc.h> -#include <string.h> -#include <ctype.h> - -#include <line.h> - -/* Return a new line structure, which will output to STREAM. WIDTH is the - maximum number of characters per line. If enough memory can't be - allocated, 0 is returned. */ -struct line * -make_line (FILE *stream, unsigned width) -{ - struct line *line = malloc (sizeof (struct line)); - if (line) - { - line->buf = malloc (width + 2); - if (line->buf) - { - line->max = line->buf + width; - line->point = line->buf; - line->stream = stream; - } - else - { - free (line); - line = 0; - } - } - return line; -} - -/* Free LINE and any resources it uses. */ -void -line_free (struct line *line) -{ - if (line->point > line->buf) - line_newline (line, 0); - free (line->buf); - free (line); -} - -/* Adds the text in STR to LINE, wrapping words as necessary to fit. - LMARGIN is the left margin used when wrapping; whitespace is deleted at - wrap-points. Newlines in STR are honoured by adding a newline and - indenting to LMARGIN; any following whitespace is kept. */ -void -line_fill (struct line *line, const char *str, unsigned lmargin) -{ - while (*str) - { - const char *word_end = str; - - while (*word_end == ' ') - word_end++; - - if (*word_end == '\n') - { - if (line_column (line) > lmargin) - line_newline (line, lmargin); - str = word_end + 1; - } - else if (*word_end) - { - const char *word_start = word_end; - while (*word_end && !isspace (*word_end)) - word_end++; - if (line_left (line, word_end - str) >= 0) - { - line_write (line, str, word_end - str); - str = word_end; - } - else - /* Word won't fit on the current line, move to the next one. */ - { - line_newline (line, lmargin); - str = word_start; /* Omit spaces when wrapping. */ - } - } - } -} - -/* Clean up after a printf to LINE, to take care of any newlines that might - have been added. ADDED is the amount the printf has added to the line. - We take care of updating LINE's point. */ -void -_line_cleanup_printf (struct line *line, unsigned added) -{ - char *point = line->point, *new_point = point + added, *last_nl = new_point; - - while (last_nl > point) - if (*--last_nl == '\n') - /* There's a newline; deal. */ - { - last_nl++; - fwrite (line->buf, 1, last_nl - line->buf, line->stream); - if (last_nl < new_point) - bcopy (last_nl, line->buf, new_point - last_nl); - new_point -= (last_nl - line->buf); - break; - } - - line->point = new_point; -} - -/* Add STR, of length LEN, to LINE. */ -void -line_write (struct line *line, const char *str, unsigned len) -{ - const char *end = memchr (str, '\n', len) ?: str + len; - unsigned line_len = end - str; - char *p = line->point, *max = line->max; - if (line_len > max - p) - line_len = max - p; - bcopy (str, p, line_len); - p += line_len; - if (line_len == len) - line->point = p; - else - { - char *buf = line->buf; - fwrite (buf, 1, p - buf, line->stream); - line->point = buf; - line_write (line, end + 1, len - line_len - 1); - } -} diff --git a/libshouldbeinlibc/=line.h b/libshouldbeinlibc/=line.h deleted file mode 100644 index 54ab15de..00000000 --- a/libshouldbeinlibc/=line.h +++ /dev/null @@ -1,128 +0,0 @@ -/* Simple output formatting functions - - Copyright (C) 1995, 1996 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> - - This file is part of the GNU Hurd. - - The GNU Hurd 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, or (at - your option) any later version. - - The GNU Hurd 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, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#ifndef __LINE_H__ -#define __LINE_H__ - -#include <stdio.h> - -struct line -{ - char *buf; - char *point, *max; - FILE *stream; -}; - -extern void -_line_cleanup_printf (struct line *line, unsigned added); - -/* Printf FMT & ARGS to LINE. */ -/* XXX This implementation is kind of bogus because it pretends to deal with - newlines in the output, but it just uses LINE's buffer for the output and - anything past the end of the buffer will get chopped. A terminating - newline will work ok though. */ -#define line_printf(line, fmt, args...) \ - ({ struct line *_line = (line); \ - _line_cleanup_printf (_line, \ - snprintf (_line->point, _line->max - _line->point, (fmt) , ##args)); \ - }) - -/* Returns the amount of free space in line after adding AMOUNT characters to - it (which will be negative if this would overflow). */ -extern inline int -line_left (struct line *line, unsigned amount) -{ - return line->max - line->point - amount; -} - -/* Return the column position of LINE's output point, which starts at 0. */ -extern inline unsigned -line_column (struct line *line) -{ - return line->point - line->buf; -} - -/* Add enough spaces to LINE to move the point to column TARGET. */ - - -extern inline void -line_indent_to (struct line *line, int target) -{ - while (line->point < line->buf + target && line->point < line->max) - *line->point++ = ' '; -} - -/* Emit the current contents of LINE and a newline to its stream, and fill - LINE with LMARGIN spaces. */ -extern inline void -line_newline (struct line *line, int lmargin) -{ - *line->point++ = '\n'; - *line->point = '\0'; - fputs (line->buf, line->stream); - line->point = line->buf; - if (lmargin) - line_indent_to (line, lmargin); -} - -/* If LINE isn't before or at column position LMARGIN, then add a newline - and indent to that position. */ -extern inline void -line_freshline (struct line *line, int lmargin) -{ - if (line_column (line) > lmargin) - line_newline (line, lmargin); -} - -/* Add a character to LINE, unless it's full. */ -extern inline int -line_putc (struct line *line, int ch) -{ - if (ch == '\n') - line_newline (line, 0); - else if (line->point < line->max) - *line->point++ = ch; - return ch; -} - -/* Adds the text in STR to LINE, wrapping words as necessary to fit. LMARGIN - is the left margin used when wrapping. */ -void line_fill (struct line *line, const char *str, unsigned lmargin); - -/* Add STR, of length LEN, to LINE. */ -void line_write (struct line *line, const char *str, unsigned len); - -/* Add STR to LINE. */ -extern inline void line_puts (struct line *line, const char *str) -{ - line_write (line, str, strlen (str)); -} - -/* Return a new line structure, which will output to STREAM. WIDTH is the - maximum number of characters per line. If enough memory can't be - allocated, 0 is returned. */ -struct line *make_line (FILE *stream, unsigned width); - -/* Free LINE and any resources it uses. */ -void line_free (struct line *line); - -#endif /* __LINE_H__ */ diff --git a/libshouldbeinlibc/=path-lookup.c b/libshouldbeinlibc/=path-lookup.c deleted file mode 100644 index b89f8d4d..00000000 --- a/libshouldbeinlibc/=path-lookup.c +++ /dev/null @@ -1,120 +0,0 @@ -/* Filename lookup using a search path - - Copyright (C) 1995 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> - - 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, 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, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include <string.h> -#include <hurd.h> -#include <hurd/lookup.h> - -/* If FILE_NAME contains a '/', or PATH is NULL, call FUN with FILE_NAME, and - return the result (if PREFIXED_NAME is non-NULL, setting *PREFIXED_NAME to - NULL). Otherwise, call FUN repeatedly with FILE_NAME prefixed with each - successive `:' separated element of PATH, returning whenever FUN returns - 0 (if PREFIXED_NAME is non-NULL, setting *PREFIXED_NAME to the resulting - prefixed path). If FUN never returns 0, return the first non-ENOENT - return value, or ENOENT if there is none. */ -error_t -file_name_path_scan (const char *file_name, const char *path, - error_t (*fun)(const char *name), - char **prefixed_name) -{ - if (path == NULL || index (file_name, '/')) - { - if (prefixed_name) - *prefixed_name = 0; - return (*fun)(file_name); - } - else - { - error_t real_err = 0; - size_t file_name_len = strlen (file_name); - - for (;;) - { - error_t err; - const char *next = index (path, ':') ?: path + strlen (path); - size_t pfx_len = next - path; - char pfxed_name[pfx_len + 2 + file_name_len + 1]; - - if (pfx_len == 0) - pfxed_name[pfx_len++] = '.'; - else - bcopy (path, pfxed_name, pfx_len); - if (pfxed_name[pfx_len - 1] != '/') - pfxed_name[pfx_len++] = '/'; - bcopy (file_name, pfxed_name + pfx_len, file_name_len + 1); - - err = (*fun)(pfxed_name); - if (err == 0) - { - if (prefixed_name) - *prefixed_name = strdup (pfxed_name); - return 0; - } - if (!real_err && err != ENOENT) - real_err = err; - - if (*next == '\0') - return real_err ?: ENOENT; - else - path = next + 1; - } - } -} - -/* Lookup FILE_NAME and return the node opened with FLAGS & MODE in result - (see hurd_file_name_lookup for details), but a simple filename (without - any directory prefixes) will be consectutively prefixed with the pathnames - in the `:' separated list PATH until one succeeds in a successful lookup. - If none succeed, then the first error that wasn't ENOENT is returned, or - ENOENT if no other errors were returned. If PREFIXED_NAME is non-NULL, - then if RESULT is looked up directly, *PREFIXED_NAME is set to NULL, and - if it is looked up using a prefix from PATH, *PREFIXED_NAME is set to - malloced storage containing the prefixed name. */ -error_t -hurd_file_name_path_lookup (error_t (*use_init_port) - (int which, - error_t (*operate) (mach_port_t)), - file_t (*get_dtable_port) (int fd), - const char *file_name, const char *path, - int flags, mode_t mode, - file_t *result, char **prefixed_name) -{ - error_t lookup (const char *name) - { - return - __hurd_file_name_lookup (use_init_port, get_dtable_port, - name, flags, mode, result); - } - return file_name_path_scan (file_name, path, lookup, prefixed_name); -} - -mach_port_t -file_name_path_lookup (const char *file_name, const char *path, - int flags, mode_t mode, char **prefixed_name) -{ - error_t err; - file_t result; - - err = hurd_file_name_path_lookup (&_hurd_ports_use, &__getdport, - file_name, path, flags, mode, - &result, prefixed_name); - - return err ? (__hurd_fail (err), MACH_PORT_NULL) : result; -} |