X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Ffilename.c;h=b78897e211bc2be19fec1e01e62e177bcce69e51;hb=16aa47dbdde420fe82032f7d2e166fdf4e974df5;hp=a07b7d18f9033a9de8ae3f263e1c1b8bd55827f2;hpb=92bfefccd465052e492f669ce561aa25b0110283;p=pspp diff --git a/src/filename.c b/src/filename.c index a07b7d18f9..b78897e211 100644 --- a/src/filename.c +++ b/src/filename.c @@ -14,12 +14,13 @@ 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., 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. */ #include #include "error.h" #include "filename.h" +#include #include #include #include @@ -28,6 +29,10 @@ #include "settings.h" #include "str.h" #include "version.h" +#include "xreadlink.h" + +#include "gettext.h" +#define _(msgid) gettext (msgid) #include "debug-print.h" @@ -38,7 +43,8 @@ #if HAVE_UNISTD_H #include #endif -#include "stat.h" +#include +#include "stat-macros.h" #endif #ifdef __WIN32__ @@ -502,7 +508,7 @@ fn_dirname (const char *filename) if (len == 1 && filename[0] == '/') p = filename + 1; else if (len && filename[len - 1] == DIR_SEPARATOR) - p = mm_find_reverse (filename, len - 1, filename + len - 1, 1); + p = buf_find_reverse (filename, len - 1, filename + len - 1, 1); else p = strrchr (filename, DIR_SEPARATOR); if (p == NULL) @@ -619,40 +625,13 @@ fn_exists_p (const char *name) #endif } -#ifdef unix -/* Stolen from libc.info but heavily modified, this is a wrapper - around readlink() that allows for arbitrary filename length. */ -char * -fn_readlink (const char *filename) -{ - int size = 128; - - for (;;) - { - char *buffer = xmalloc (size); - int nchars = readlink (filename, buffer, size); - if (nchars == -1) - { - free (buffer); - return NULL; - } - - if (nchars < size - 1) - { - buffer[nchars] = 0; - return buffer; - } - free (buffer); - size *= 2; - } -} -#else /* Not UNIX. */ +/* Returns the symbolic link value for FILENAME as a dynamically + allocated buffer, or a null pointer on failure. */ char * fn_readlink (const char *filename) { - return NULL; + return xreadlink (filename, 32); } -#endif /* Not UNIX. */ /* Environment variables. */ @@ -712,7 +691,7 @@ fn_open (const char *fn, const char *mode) #ifdef unix if (fn[0] == '|') { - if (safer_mode()) + if (get_safer_mode ()) return safety_violation (fn); return popen (&fn[1], mode); @@ -722,7 +701,7 @@ fn_open (const char *fn, const char *mode) char *s; FILE *f; - if (safer_mode()) + if (get_safer_mode ()) return safety_violation (fn); s = local_alloc (strlen (fn));