diff options
author | Karel Zak <kzak@redhat.com> | 2006-12-07 00:25:41 +0100 |
---|---|---|
committer | Karel Zak <kzak@redhat.com> | 2006-12-07 00:25:41 +0100 |
commit | eb63b9b8f4cecb34c2478282567862bc48ef256d (patch) | |
tree | 99243f8eecb44c2bb6a559982b99c680fcb649e7 /lib | |
parent | 7eda085c41faa3445b4b168ce78ab18dab87d98a (diff) | |
download | util-linux-eb63b9b8f4cecb34c2478282567862bc48ef256d.tar.gz |
Imported from util-linux-2.10f tarball.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/README.widechar | 18 | ||||
-rw-r--r-- | lib/err.c | 110 | ||||
-rw-r--r-- | lib/err.h | 70 | ||||
-rw-r--r-- | lib/errs.h | 16 | ||||
-rw-r--r-- | lib/pathnames.h | 96 | ||||
-rw-r--r-- | lib/widechar.h | 41 |
6 files changed, 171 insertions, 180 deletions
diff --git a/lib/README.widechar b/lib/README.widechar new file mode 100644 index 00000000..5a8179bb --- /dev/null +++ b/lib/README.widechar @@ -0,0 +1,18 @@ +From haible@ilog.fr Mon Sep 20 15:34:21 1999 + +Hello Andries, + +Here is a patch for adding multi-byte locale support to a few programs +found in util-linux-2.9u. With these patches, the programs + + col colcrt colrm column rev ul + +now work correctly in UTF-8 locales. This is done by using the ISO C / SUSV2 +i18n functions, therefore they will become effective when glibc-2.2 comes +out. For the moment, you can test the patches by + 1. defining ENABLE_WIDECHAR in defines.h + 2. Change the #if 0 to #if 1 in lib/widechar.h + 3. Modify your CFLAGS and LDFLAGS to include the directories where libutf8 + is installed. + + @@ -31,17 +31,13 @@ * SUCH DAMAGE. */ -#include <err.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> +#include <stdarg.h> #include <string.h> +#include "errs.h" -#ifdef __STDC__ -#include <stdarg.h> -#else -#include <varargs.h> -#endif #include "../defines.h" #ifdef HAVE_progname @@ -50,101 +46,63 @@ extern char *__progname; /* Program name, from crt0. */ char *__progname = "foo"; /* probably libc4 */ #endif -__dead void -#ifdef __STDC__ -err(int eval, const char *fmt, ...) -#else -err(eval, fmt, va_alist) - int eval; - const char *fmt; - va_dcl -#endif -{ +/* Some compilers complain "null format string" upon err(1,NULL) */ +/* Make them happy with a separate routine. */ +void +err_nomsg(int exitval) { + (void)fprintf(stderr, "%s: %s\n", __progname, strerror(errno)); + exit(exitval); +} + +void +err(int exitval, const char *fmt, ...) { va_list ap; -#if __STDC__ va_start(ap, fmt); -#else - va_start(ap); -#endif - verr(eval, fmt, ap); + verr(exitval, fmt, ap); va_end(ap); } -__dead void -verr(eval, fmt, ap) - int eval; - const char *fmt; - va_list ap; -{ +void +verr(int exitval, const char *fmt, va_list ap) { int sverrno; sverrno = errno; (void)fprintf(stderr, "%s: ", __progname); - if (fmt != NULL) { + if (fmt != NULL && *fmt != 0) { (void)vfprintf(stderr, fmt, ap); (void)fprintf(stderr, ": "); } (void)fprintf(stderr, "%s\n", strerror(sverrno)); - exit(eval); + exit(exitval); } -__dead void -#if __STDC__ -errx(int eval, const char *fmt, ...) -#else -errx(eval, fmt, va_alist) - int eval; - const char *fmt; - va_dcl -#endif -{ +void +errx(int exitval, const char *fmt, ...) { va_list ap; -#if __STDC__ va_start(ap, fmt); -#else - va_start(ap); -#endif - verrx(eval, fmt, ap); + verrx(exitval, fmt, ap); va_end(ap); } -__dead void -verrx(eval, fmt, ap) - int eval; - const char *fmt; - va_list ap; -{ +void +verrx(int exitval, const char *fmt, va_list ap) { (void)fprintf(stderr, "%s: ", __progname); if (fmt != NULL) (void)vfprintf(stderr, fmt, ap); (void)fprintf(stderr, "\n"); - exit(eval); + exit(exitval); } void -#if __STDC__ -warn(const char *fmt, ...) -#else -warn(fmt, va_alist) - const char *fmt; - va_dcl -#endif -{ +warn(const char *fmt, ...) { va_list ap; -#if __STDC__ va_start(ap, fmt); -#else - va_start(ap); -#endif vwarn(fmt, ap); va_end(ap); } void -vwarn(fmt, ap) - const char *fmt; - va_list ap; -{ +vwarn(const char *fmt, va_list ap) { int sverrno; sverrno = errno; @@ -157,29 +115,15 @@ vwarn(fmt, ap) } void -#ifdef __STDC__ -warnx(const char *fmt, ...) -#else -warnx(fmt, va_alist) - const char *fmt; - va_dcl -#endif -{ +warnx(const char *fmt, ...) { va_list ap; -#ifdef __STDC__ va_start(ap, fmt); -#else - va_start(ap); -#endif vwarnx(fmt, ap); va_end(ap); } void -vwarnx(fmt, ap) - const char *fmt; - va_list ap; -{ +vwarnx(const char *fmt, va_list ap) { (void)fprintf(stderr, "%s: ", __progname); if (fmt != NULL) (void)vfprintf(stderr, fmt, ap); diff --git a/lib/err.h b/lib/err.h deleted file mode 100644 index da4be150..00000000 --- a/lib/err.h +++ /dev/null @@ -1,70 +0,0 @@ -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)err.h 8.1 (Berkeley) 6/2/93 - */ - -#ifndef _ERR_H_ -#define _ERR_H_ - -#ifdef __linux__ -#include <stdarg.h> -#define _BSD_VA_LIST_ va_list -#define __dead /* */ -#else -/* - * Don't use va_list in the err/warn prototypes. Va_list is typedef'd in two - * places (<machine/varargs.h> and <machine/stdarg.h>), so if we include one - * of them here we may collide with the utility's includes. It's unreasonable - * for utilities to have to include one of them to include err.h, so we get - * _BSD_VA_LIST_ from <machine/ansi.h> and use it. - */ -#include <machine/ansi.h> -#endif -#include <sys/cdefs.h> - -__BEGIN_DECLS -__dead void err __P((int, const char *, ...)); -__dead void verr __P((int, const char *, _BSD_VA_LIST_)); -__dead void errx __P((int, const char *, ...)); -__dead void verrx __P((int, const char *, _BSD_VA_LIST_)); -void warn __P((const char *, ...)); -void vwarn __P((const char *, _BSD_VA_LIST_)); -void warnx __P((const char *, ...)); -void vwarnx __P((const char *, _BSD_VA_LIST_)); -__END_DECLS - -#ifdef __linux__ -#undef _BSD_VA_LIST_ -#endif - -#endif /* !_ERR_H_ */ diff --git a/lib/errs.h b/lib/errs.h new file mode 100644 index 00000000..7961880d --- /dev/null +++ b/lib/errs.h @@ -0,0 +1,16 @@ +#ifndef _ERR_H_ +#define _ERR_H_ + +#include <stdarg.h> + +void err_nomsg (int); +void err (int, const char *, ...); +void verr (int, const char *, va_list); +void errx (int, const char *, ...); +void verrx (int, const char *, va_list); +void warn (const char *, ...); +void vwarn (const char *, va_list); +void warnx (const char *, ...); +void vwarnx (const char *, va_list); + +#endif /* !_ERR_H_ */ diff --git a/lib/pathnames.h b/lib/pathnames.h index ab7b97dc..60797f94 100644 --- a/lib/pathnames.h +++ b/lib/pathnames.h @@ -1,43 +1,78 @@ /* - * Copyright (c) 1989 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by the University of California, Berkeley. The name of the - * University may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * + * Vaguely based on * @(#)pathnames.h 5.3 (Berkeley) 5/9/89 - * - * Changed: Sun Nov 21 12:30:54 1993 by faith@cs.unc.edu - * Changed: Wed Jun 22 20:47:27 1994 by faith@cs.unc.edu, based on changes - * from poe@daimi.aau.dk - * Changed: Wed Jun 22 22:50:13 1994 by faith@cs.unc.edu - * Changed: Sat Feb 4 16:02:10 1995 by faith@cs.unc.edu - * Changed: Tue Jul 2 09:37:36 1996 by janl@math.uio.no, axp patches - * Changed: Thu Nov 9 21:58:36 1995 by joey@infodrom.north.de + * This code is in the public domain. */ +#include <paths.h> #ifndef __STDC__ # error "we need an ANSI compiler" #endif -/* The paths for some of these are wrong in /usr/include/paths.h, but we - re-define them here. */ +/* The paths for some of these are wrong in /usr/include/paths.h, + but we re-define them here. */ +/* Used in login.c, agetty.c, simpleinit.c, shutdown.c, write.c */ #undef _PATH_UTMP +/* Used in login.c, agetty.c, simpleinit.c, shutdown.c, last.c */ #undef _PATH_WTMP +/* These four are used in login.c only */ #undef _PATH_DEFPATH #undef _PATH_DEFPATH_ROOT #undef _PATH_LASTLOG -#undef _PATH_MAILDIR + +/* + * HISTORY + * +What is the history of these six, and related defines? +------------------------------------------------------------------------ +_PATH_UTMP and UTMP_FILE and UTMP_FILENAME: + /etc/utmp > /var/adm/utmp > /var/run/utmp. +Traditionally we have /etc/utmp. +In <paths.h> we have /etc/utmp, but since 4.6.0 /var/adm/utmp +and since 5.0.9 (and in glibc2) /var/run/utmp. +In login/pathnames.h we have /etc/utmp, but since 4.6.6 /var/adm/utmp. +In <utmp.h> UTMP_FILE is defined as /etc/utmp, but in 4.6.* as _PATH_UTMP. + +_PATH_WTMP and WTMP_FILE and WTMP_FILENAME: + /etc/wtmp > /usr/adm/wtmp > /var/adm/wtmp > /var/log/wtmp. +Traditionally we have /etc/wtmp. +In <paths.h> we have /usr/adm/wtmp, but since 4.5.13 /var/adm/wtmp, +and since 5.0.9 (and in glibc2) /var/log/wtmp. +In login/pathnames.h. we have /etc/wtmp, but since 4.6.6 /var/adm/wtmp. +In <utmp.h> WTMP_FILE is defined as /usr/adm/wtmp, but in 4.5.* as +/var/adm/wtmp, and in 4.6.* as _PATH_WTMP. + +_PATH_DEFPATH) +Long ago this was ".:/bin:/usr/bin". +In <paths.h> libc 4.4.1-4.4.4 have "/usr/bin:/bin" +and libc 4.5.21-5.4.23 have "/usr/local/bin:/usr/bin:/bin:." +and libc 5.4.38-5.4.46 have "/usr/local/bin:/usr/bin:/bin". +In login/pathnames.h libc4 and libc5 have "/usr/local/bin:/bin:/usr/bin:." + +_PATH_DEFPATH_ROOT) +Long ago this was identical to _PATH_DEFPATH. +In <paths.h> no definition is present before libc 4.5.13. +Libc 4.5.13 has "/bin:/usr/bin:/etc" +Libc 4.5.14-5.4.46 have "/sbin:/bin:/usr/sbin:/usr/bin" +In login/pathnames.h libc4 and libc5 have "/bin:/usr/bin:/etc" + +_PATH_LASTLOG) + /etc/lastlog > /usr/adm/lastlog > /var/adm/lastlog > /var/log/lastlog. +Traditionally we have /etc/lastlog. +In <bsd/utmp.h> libc 4.4.1-4.5.12 have /usr/adm/lastlog, 4.5.13 and +later have /var/adm/lastlog. +In paths.h all libc5 and glibc2 versions have /var/log/lastlog. +In login/pathnames.h all libc4 and libc5 versions have /usr/adm/lastlog. + +_PATH_MAILDIR) + /usr/spool/mail > /var/spool/mail > /var/mail. +Traditionally we have /usr/spool/mail. +In <paths.h> we have /usr/spool/mail, but since libc 4.5.13 /var/spool/mail. +In login/pathnames.h all libc4 versions have /var/spool/mail. +Libc5 and glibc 2.0-2.1 have /var/spool/mail, but glibc 2.1.1 has /var/mail. +------------------------------------------------------------------------*/ + #ifndef SBINDIR #define SBINDIR "/sbin" @@ -73,7 +108,10 @@ #define _PATH_DEFPATH_ROOT SBINDIR ":/bin:" USRSBINDIR ":/usr/bin" #define _PATH_HUSHLOGIN ".hushlogin" #define _PATH_LASTLOG LOGDIR "/lastlog" + +#ifndef _PATH_MAILDIR #define _PATH_MAILDIR VARPATH "/spool/mail" +#endif #define _PATH_MOTDFILE "/etc/motd" #define _PATH_NOLOGIN "/etc/nologin" @@ -87,18 +125,22 @@ #define _PATH_SECURE "/etc/securesingle" #define _PATH_USERTTY "/etc/usertty" +/* used in login-utils/shutdown.c */ #define _PATH_MTAB "/etc/mtab" #define _PATH_UMOUNT "/bin/umount" #define UMOUNT_ARGS "umount", "-a" #define SWAPOFF_ARGS "swapoff", "-a" +/* used in login-utils/setpwnam.h and login-utils/islocal.c */ #define _PATH_PASSWD "/etc/passwd" + +/* used in login-utils/setpwnam.h */ #define _PATH_PTMP "/etc/ptmp" #define _PATH_PTMPTMP "/etc/ptmptmp" - #define _PATH_GROUP "/etc/group" #define _PATH_GTMP "/etc/gtmp" #define _PATH_GTMPTMP "/etc/gtmptmp" +/* used in misc-utils/look.c */ #define _PATH_WORDS "/usr/dict/words" #define _PATH_WORDS_ALT "/usr/dict/web2" diff --git a/lib/widechar.h b/lib/widechar.h new file mode 100644 index 00000000..a8d28829 --- /dev/null +++ b/lib/widechar.h @@ -0,0 +1,41 @@ +/* Declarations for wide characters */ +/* This file must be included last because the redefinition of wchar_t may + cause conflicts when system include files were included after it. */ + +#include "../defines.h" /* for ENABLE_WIDECHAR */ + +#ifdef ENABLE_WIDECHAR + +# include <wchar.h> +# include <wctype.h> +#if 0 /* for testing on platforms without built-in wide character support */ +# include <libutf8.h> +#endif + +#else + +# include <ctype.h> + /* Fallback for types */ +# define wchar_t char +# define wint_t int +# define WEOF EOF + /* Fallback for input operations */ +# define fgetwc fgetc +# define getwc getc +# define getwchar getchar +# define fgetws fgets + /* Fallback for output operations */ +# define fputwc fputc +# define putwc putc +# define putwchar putchar +# define fputws fputs + /* Fallback for character classification */ +# define iswgraph isgraph +# define iswprint isprint +# define iswspace isspace + /* Fallback for string functions */ +# define wcschr strchr +# define wcsdup strdup +# define wcslen strlen + +#endif |