X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Faccess.c;h=44c7e1b2f5d129d366bcaf45341eaadbbbf39eb5;hp=6fbe9217604556aec637c048d8d66825c20b1100;hb=a8987e73ec254703634802b4f7ee30d3a485524d;hpb=c633e5103a29a38532cf1925257b91cea33fd090 diff --git a/ncurses/tinfo/access.c b/ncurses/tinfo/access.c index 6fbe9217..44c7e1b2 100644 --- a/ncurses/tinfo/access.c +++ b/ncurses/tinfo/access.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998,2001,2003 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -27,30 +27,68 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey 1998,2000 * + * Author: Thomas E. Dickey 1998,2000,2001 * ****************************************************************************/ #include #include +#include -MODULE_ID("$Id: access.c,v 1.4 2000/10/08 01:25:06 tom Exp $") +MODULE_ID("$Id: access.c,v 1.10 2003/07/05 19:31:28 tom Exp $") -char * -_nc_basename(char *path) +#define LOWERCASE(c) ((isalpha(UChar(c)) && isupper(UChar(c))) ? tolower(UChar(c)) : (c)) + +NCURSES_EXPORT(char *) +_nc_rootname(char *path) { - char *result = strrchr(path, '/'); + char *result = _nc_basename(path); +#if !defined(MIXEDCASE_FILENAMES) || defined(PROG_EXT) + static char *temp; + char *s; + + temp = strdup(result); + result = temp; +#if !defined(MIXEDCASE_FILENAMES) + int n; + for (s = result; *s != '\0'; ++s) { + *s = LOWERCASE(*s); + } +#endif +#if defined(PROG_EXT) + if ((s = strrchr(result, '.')) != 0) { + if (!strcmp(s, PROG_EXT)) + *s = '\0'; + } +#endif +#endif + return result; +} + +/* + * Return index of the basename + */ +NCURSES_EXPORT(unsigned) +_nc_pathlast(const char *path) +{ + const char *test = strrchr(path, '/'); #ifdef __EMX__ - if (result == 0) - result = strrchr(path, '\\'); + if (test == 0) + test = strrchr(path, '\\'); #endif - if (result == 0) - result = path; + if (test == 0) + test = path; else - result++; - return result; + test++; + return (test - path); +} + +NCURSES_EXPORT(char *) +_nc_basename(char *path) +{ + return path + _nc_pathlast(path); } -int +NCURSES_EXPORT(int) _nc_access(const char *path, int mode) { if (access(path, mode) < 0) { @@ -78,7 +116,7 @@ _nc_access(const char *path, int mode) * Returns true if we allow application to use environment variables that are * used for searching lists of directories, etc. */ -int +NCURSES_EXPORT(int) _nc_env_access(void) { #if HAVE_ISSETUGID @@ -86,9 +124,9 @@ _nc_env_access(void) return FALSE; #elif HAVE_GETEUID && HAVE_GETEGID if (getuid() != geteuid() - || getgid() != getegid()) + || getgid() != getegid()) return FALSE; #endif - return getuid() != 0; /* ...finally, disallow root */ + return getuid() != 0 && geteuid() != 0; /* ...finally, disallow root */ } #endif