- /* Then make a buffer that big. */
- fn2 = xmalloc (len);
- success = GetFullPathName (fn1, len, fn2, NULL);
- if (success >= len || success == 0)
- {
- free (fn2);
- fn2 = xstrdup (fn1);
- return fn2;
- }
- return fn2;
-}
-#elif __BORLANDC__
-char *
-fn_normalize (const char *fn1)
-{
- char *fn2 = _fullpath (NULL, fn1, 0);
- if (fn2)
- {
- char *cp;
- for (cp = fn2; *cp; cp++)
- *cp = toupper ((unsigned char) (*cp));
- return fn2;
- }
- return xstrdup (fn1);
-}
-#elif __DJGPP__
-char *
-fn_normalize (const char *fn1)
-{
- char *fn2 = xmalloc (1024);
- _fixpath (fn1, fn2);
- fn2 = xrealloc (fn2, strlen (fn2) + 1);
- return fn2;
-}
-#else /* not Lose32, Unix, or DJGPP */
-char *
-fn_normalize (const char *fn)
-{
- return xstrdup (fn);
-}
-#endif /* not Lose32, Unix, or DJGPP */
-
-/* Returns the directory part of FILE_NAME, as a malloc()'d
- string. */
-char *
-fn_dir_name (const char *file_name)
-{
- const char *p;
- char *s;
- size_t len;
-
- len = strlen (file_name);
- if (len == 1 && file_name[0] == '/')
- p = file_name + 1;
- else if (len && file_name[len - 1] == '/')
- p = buf_find_reverse (file_name, len - 1, file_name + len - 1, 1);
- else
- p = strrchr (file_name, '/');
- if (p == NULL)
- p = file_name;
-
- s = xmalloc (p - file_name + 1);
- memcpy (s, file_name, p - file_name);
- s[p - file_name] = 0;
-
- return s;
-}
-
-/* Returns the extension part of FILE_NAME as a malloc()'d string.
- If FILE_NAME does not have an extension, returns an empty
- string. */
-char *
-fn_extension (const char *file_name)
-{
- const char *extension = strrchr (file_name, '.');
- if (extension == NULL)
- extension = "";
- return xstrdup (extension);
-}
-\f
-#if unix
-/* Returns the current working directory, as a malloc()'d string.
- From libc.info. */
-char *
-fn_get_cwd (void)
-{
- int size = 100;
- char *buffer = xmalloc (size);
-
- for (;;)
- {
- char *value = getcwd (buffer, size);
- if (value != 0)
- return buffer;
-
- size *= 2;
- free (buffer);
- buffer = xmalloc (size);
- }
-}
-#else
-char *
-fn_get_cwd (void)
-{
- int size = 2;
- char *buffer = xmalloc (size);
- if ( buffer)
- {
- buffer[0]='.';
- buffer[1]='\0';
- }
-
- return buffer;
-
-}
-#endif
-\f
-/* Find out information about files. */
-
-/* Returns nonzero iff NAME specifies an absolute file name. */
-int
-fn_is_absolute (const char *name)
-{
-#ifdef unix
- if (name[0] == '/'
- || !strncmp (name, "./", 2)
- || !strncmp (name, "../", 3)
- || name[0] == '~')
- return 1;
-#elif defined (__MSDOS__)
- if (name[0] == '\\'
- || !strncmp (name, ".\\", 2)
- || !strncmp (name, "..\\", 3)
- || (name[0] && name[1] == ':'))
- return 1;
-#endif
-
- return 0;