+Mon Feb 19 10:53:21 2007 John McCabe-Dansted <gmatht@gmail.com>
+ Ben Pfaff <blp@gnu.org>
+
+ * file-name.c: Mingw compatibility fixes.
+ (fn_search_path): Use ISSLASH instead of comparing against '/'
+ directly.
+ (fn_dir_name): Use dir_name from gnulib.
+ (fn_is_absolute): Use IS_ABSOLUTE_FILE_NAME from gnulib.
+ (fn_get_identity): Use GetFullPathName instead of canonicalize
+ from gnulib, because the latter does not fully support
+ Windows-style path names. Use this implementation based on the
+ detected presence of Windows instead of the absence of Unix, since
+ the new implementation is Windows-specific.
+ (fn_compare_file_identities): In Windows implementation, compare
+ names case-insensitively.
+
Sun Feb 18 13:28:02 2007 Ben Pfaff <blp@gnu.org>
* make-file.c: Don't include mkstemp.h, because gnulib now causes
/* PSPP - computes sample statistics.
- Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2006, 2007 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
#include <config.h>
-#include "file-name.h"
+#include <data/file-name.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
-#include "canonicalize.h"
#include "intprops.h"
#include "minmax.h"
-#include "settings.h"
+#include "dirname.h"
#include <libpspp/alloc.h>
#include <libpspp/message.h>
-#include <libpspp/message.h>
+#include <data/settings.h>
#include <libpspp/str.h>
#include <libpspp/verbose-msg.h>
#include <libpspp/version.h>
#include <unistd.h>
#include <sys/stat.h>
+
+#if defined _WIN32 || defined __WIN32__
+#define WIN32_LEAN_AND_MEAN /* avoid including junk */
+#include <windows.h>
+#endif
\f
/* Initialization. */
/* Construct file name. */
ds_clear (&file);
ds_put_substring (&file, dir);
- if (!ds_is_empty (&file) && ds_last (&file) != '/')
+ if (!ds_is_empty (&file) && !ISSLASH (ds_last (&file)))
ds_put_char (&file, '/');
ds_put_cstr (&file, base_name);
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;
+ return dir_name (file_name);
}
/* Returns the extension part of FILE_NAME as a malloc()'d string.
bool
fn_is_absolute (const char *name)
{
- return name[0] == '/';
+ return IS_ABSOLUTE_FILE_NAME (name);
}
/* Returns true if FILE_NAME is a virtual file that doesn't
return fclose (f);
}
-#ifdef unix
+#if !(defined _WIN32 || defined __WIN32__)
/* A file's identity. */
struct file_identity
{
else
return a->inode < b->inode ? -1 : a->inode > b->inode;
}
-#else /* not unix */
+#else /* Windows */
/* A file's identity. */
struct file_identity
{
fn_get_identity (const char *file_name)
{
struct file_identity *identity = xmalloc (sizeof *identity);
- char *cname = canonicalize_filename_mode (file_name, CAN_MISSING);
- if (cname == NULL)
- cname = xstrdup (file_name);
- identity->normalized_file_name = cname;
+ char cname[PATH_MAX];
+
+ if (GetFullPathName (file_name, sizeof cname, cname, NULL))
+ identity->normalized_file_name = xstrdup (cname);
+ else
+ identity->normalized_file_name = xstrdup (file_name);
+
return identity;
}
fn_compare_file_identities (const struct file_identity *a,
const struct file_identity *b)
{
- return strcmp (a->normalized_file_name, b->normalized_file_name);
+ return strcasecmp (a->normalized_file_name, b->normalized_file_name);
}
-#endif /* not unix */
+#endif /* Windows */