(cwcsdup1): New function.
* cygheap.h (cygheap_user::get_windows_id): New method returning PWCHAR.
(cwcsdup): Declare.
(cwcsdup1): Declare.
* registry.cc (get_registry_hive_path): Use WCHAR instead of char
throughout.
(load_registry_hive): Ditto.
* registry.h (get_registry_hive_path): Change declaration accordingly.
(load_registry_hive): Ditto.
* sec_helper.cc (cygpsid::string): New method returning PWCHAR.
* security.h (cygpsid::string): Declare.
* syscalls.cc (seteuid32): Convert local name var to WCHAR.
* uinfo.cc (cygheap_user::env_userprofile): Convert local name buffers
to WCHAR. Call sys_wcstombs_alloc to generate puserprof buffer.
* winsup.h: Fix comment.
(NT_MAX_PATH): New definition for maximum internal path length.
Use throughout where appropriate.
* include/limits.h (PATH_MAX): Set to 4096 as on Linux.
+2008-02-14 Corinna Vinschen <corinna@vinschen.de>
+
+ * cygheap.cc (cwcsdup): New function.
+ (cwcsdup1): New function.
+ * cygheap.h (cygheap_user::get_windows_id): New method returning PWCHAR.
+ (cwcsdup): Declare.
+ (cwcsdup1): Declare.
+ * registry.cc (get_registry_hive_path): Use WCHAR instead of char
+ throughout.
+ (load_registry_hive): Ditto.
+ * registry.h (get_registry_hive_path): Change declaration accordingly.
+ (load_registry_hive): Ditto.
+ * sec_helper.cc (cygpsid::string): New method returning PWCHAR.
+ * security.h (cygpsid::string): Declare.
+ * syscalls.cc (seteuid32): Convert local name var to WCHAR.
+ * uinfo.cc (cygheap_user::env_userprofile): Convert local name buffers
+ to WCHAR. Call sys_wcstombs_alloc to generate puserprof buffer.
+
+ * winsup.h: Fix comment.
+ (NT_MAX_PATH): New definition for maximum internal path length.
+ Use throughout where appropriate.
+ * include/limits.h (PATH_MAX): Set to 4096 as on Linux.
+
2008-02-13 Christopher Faylor <me+cygwin@cgf.cx>
* configure.in: Remove non-working options.
#include "sigproc.h"
#include "pinfo.h"
#include <unistd.h>
+#include <wchar.h>
init_cygheap NO_COPY *cygheap;
void NO_COPY *cygheap_max;
return ccalloc (x, n, size, "ccalloc");
}
+extern "C" PWCHAR __stdcall
+cwcsdup (const PWCHAR s)
+{
+ MALLOC_CHECK;
+ PWCHAR p = (PWCHAR) cmalloc (HEAP_STR, wcslen (s) + 1);
+ if (!p)
+ return NULL;
+ wcpcpy (p, s);
+ MALLOC_CHECK;
+ return p;
+}
+
+extern "C" PWCHAR __stdcall
+cwcsdup1 (const PWCHAR s)
+{
+ MALLOC_CHECK;
+ PWCHAR p = (PWCHAR) cmalloc (HEAP_1_STR, wcslen (s) + 1);
+ if (!p)
+ return NULL;
+ wcpcpy (p, s);
+ MALLOC_CHECK;
+ return p;
+}
+
extern "C" char *__stdcall
cstrdup (const char *s)
{
if (internal_token != NO_IMPERSONATION)
CloseHandle (internal_token);
}
- char * get_windows_id (char * buf)
+ PWCHAR get_windows_id (PWCHAR buf)
+ {
+ return effec_cygsid.string (buf);
+ }
+ char *get_windows_id (char *buf)
{
return effec_cygsid.string (buf);
}
DWORD get_drive (char * dst)
{
cwd_lock.acquire ();
- DWORD ret = sys_wcstombs (dst, PATH_MAX, win32.Buffer, drive_length);
+ DWORD ret = sys_wcstombs (dst, NT_MAX_PATH, win32.Buffer, drive_length);
cwd_lock.release ();
return ret;
}
void *__stdcall cmalloc_abort (cygheap_types, DWORD) __attribute__ ((regparm(2)));
void *__stdcall crealloc_abort (void *, DWORD) __attribute__ ((regparm(2)));
void *__stdcall ccalloc_abort (cygheap_types, DWORD, DWORD) __attribute__ ((regparm(3)));
+PWCHAR __stdcall cwcsdup (const PWCHAR) __attribute__ ((regparm(1)));
+PWCHAR __stdcall cwcsdup1 (const PWCHAR) __attribute__ ((regparm(1)));
char *__stdcall cstrdup (const char *) __attribute__ ((regparm(1)));
char *__stdcall cstrdup1 (const char *) __attribute__ ((regparm(1)));
void __stdcall cfree_and_set (char *&, char * = NULL) __attribute__ ((regparm(2)));
static void
initial_env ()
{
- char buf[PATH_MAX];
+ char buf[NT_MAX_PATH];
if (GetEnvironmentVariable ("CYGWIN_TESTING", buf, sizeof (buf) - 1))
_cygwin_testing = 1;
}
if (GetEnvironmentVariable ("CYGWIN_DEBUG", buf, sizeof (buf) - 1))
{
- char buf1[PATH_MAX];
- len = GetModuleFileName (NULL, buf1, PATH_MAX);
+ char buf1[NT_MAX_PATH];
+ len = GetModuleFileName (NULL, buf1, NT_MAX_PATH);
strlwr (buf1);
strlwr (buf);
char *p = strpbrk (buf, ":=");
win32 style. */
if ((strchr (__argv[0], ':')) || (strchr (__argv[0], '\\')))
{
- char *new_argv0 = (char *) malloc (PATH_MAX);
+ char *new_argv0 = (char *) malloc (NT_MAX_PATH);
cygwin_conv_to_posix_path (__argv[0], new_argv0);
__argv[0] = (char *) realloc (new_argv0, strlen (new_argv0) + 1);
}
dll *
dll_list::alloc (HINSTANCE h, per_process *p, dll_type type)
{
- char name[PATH_MAX];
+ char name[NT_MAX_PATH];
DWORD namelen = GetModuleFileName (h, name, sizeof (name));
/* Already loaded? */
int count;
dll_type type;
int namelen;
- char name[PATH_MAX];
+ char name[NT_MAX_PATH];
void detach ();
int init ();
};
}
else
{
- char buf[PATH_MAX];
+ char buf[NT_MAX_PATH];
strcpy (buf, name + namelen);
towin32 (in_posix, buf);
native = (char *) realloc (native, namelen + 1 + strlen (buf));
/* Turn all the items from c:<foo>;<bar> into their
mounted equivalents - if there is one. */
- char outenv[1 + len + PATH_MAX];
+ char outenv[1 + len + NT_MAX_PATH];
memcpy (outenv, src, len);
char *newvalue = outenv + len;
if (!conv->toposix (value, newvalue) || _impure_ptr->_errno != EIDRM)
#define CALL_HANDLER_RETRY 20
-char debugger_command[2 * PATH_MAX + 20];
+char debugger_command[2 * NT_MAX_PATH + 20];
extern "C" {
extern void sigdelayed ();
return;
}
- char pgm[PATH_MAX];
- if (!GetModuleFileName (NULL, pgm, PATH_MAX))
+ char pgm[NT_MAX_PATH];
+ if (!GetModuleFileName (NULL, pgm, NT_MAX_PATH))
strcpy (pgm, "cygwin1.dll");
for (char *p = strchr (pgm, '\\'); p; p = strchr (p, '\\'))
*p = '/';
case PROCESS_EXENAME:
case PROCESS_EXE:
{
- filebuf = (char *) crealloc_abort (filebuf, bufalloc = PATH_MAX);
+ filebuf = (char *) crealloc_abort (filebuf, bufalloc = NT_MAX_PATH);
if (p->process_state & PID_EXITED)
strcpy (filebuf, "<defunct>");
else
DWORD_PTR wset_size;
DWORD_PTR *workingset = NULL;
MODULEINFO info;
- WCHAR modname[PATH_MAX];
- char posix_modname[PATH_MAX];
+ WCHAR modname[NT_MAX_PATH];
+ char posix_modname[NT_MAX_PATH];
if (!EnumProcessModules (proc, NULL, 0, &needed))
{
strcpy (access, "r--p");
struct __stat64 st;
if (mount_table->conv_to_posix_path (modname, posix_modname, 0))
- sys_wcstombs (posix_modname, PATH_MAX, modname);
+ sys_wcstombs (posix_modname, NT_MAX_PATH, modname);
if (stat64 (posix_modname, &st))
{
st.st_dev = 0;
#undef NAME_MAX
#define NAME_MAX 255
-/* Maximum length of a path including trailing NUL.
- (32767 - max. native NT path prefix) */
+/* Maximum length of a path given to API functions including trailing NUL.
+ Deliberately set to the same default value as on Linux. Internal paths
+ may be longer. */
#undef PATH_MAX
-#define PATH_MAX 32760
+#define PATH_MAX 4096
/* # of bytes in a pipe buf. This is the max # of bytes which can be
written to a pipe in one atomic operation. */
__gid32_t gid32;
/* Only available if version >= EXTERNAL_PINFO_VERSION_32_LP */
- char progname_long[PATH_MAX];
+ char progname_long[NT_MAX_PATH];
};
#endif /*__CYGWIN__*/
#endif /*WINVER*/
changed = true;
}
}
- char buf[PATH_MAX];
- sys_wcstombs (buf, PATH_MAX, src_path);
+ char buf[NT_MAX_PATH];
+ sys_wcstombs (buf, NT_MAX_PATH, src_path);
int ret = conv_to_posix_path (buf, posix_path, keep_rel_p);
if (changed)
src_path[0] = L'C';
if (!posix_cwd)
{
- posix_cwd = (const char *) alloca (PATH_MAX);
+ posix_cwd = (const char *) alloca (NT_MAX_PATH);
mount_table->conv_to_posix_path (win32.Buffer, (char *) posix_cwd, 0);
}
posix = (char *) crealloc_abort (posix, strlen (posix_cwd) + 1);
char *tocopy;
if (!need_posix)
{
- tocopy = (char *) alloca (PATH_MAX);
- sys_wcstombs (tocopy, PATH_MAX, win32.Buffer, win32.Length);
+ tocopy = (char *) alloca (NT_MAX_PATH);
+ sys_wcstombs (tocopy, NT_MAX_PATH, win32.Buffer, win32.Length);
}
else
tocopy = posix;
commune_process (void *arg)
{
siginfo_t& si = *((siginfo_t *) arg);
- char path[PATH_MAX];
+ char path[NT_MAX_PATH];
DWORD nr;
HANDLE& tothem = si._si_commune._si_write_handle;
HANDLE process_sync =
case PICOM_CWD:
{
sigproc_printf ("processing PICOM_CWD");
- unsigned int n = strlen (cygheap->cwd.get (path, 1, 1, PATH_MAX)) + 1;
+ unsigned int n = strlen (cygheap->cwd.get (path, 1, 1, NT_MAX_PATH)) + 1;
if (!WriteFile (tothem, &n, sizeof n, &nr, NULL))
sigproc_printf ("WriteFile sizeof cwd failed, %E");
else if (!WriteFile (tothem, path, n, &nr, NULL))
if (cfd < 0)
s = cstrdup ("");
else
- s = cfd->get_proc_fd_name ((char *) cmalloc_abort (HEAP_COMMUNE, PATH_MAX));
+ s = cfd->get_proc_fd_name ((char *) cmalloc_abort (HEAP_COMMUNE, NT_MAX_PATH));
n = strlen (s) + 1;
}
return s;
}
else
{
- s = (char *) cmalloc_abort (HEAP_COMMUNE, PATH_MAX);
- cygheap->cwd.get (s, 1, 1, PATH_MAX);
+ s = (char *) cmalloc_abort (HEAP_COMMUNE, NT_MAX_PATH);
+ cygheap->cwd.get (s, 1, 1, NT_MAX_PATH);
n = strlen (s) + 1;
}
return s;
DWORD dwProcessId;
/* Used to spawn a child for fork(), among other things. */
- char progname[PATH_MAX];
+ char progname[NT_MAX_PATH];
/* User information.
The information is derived from the GetUserName system call,
#include "fhandler.h"
#include "dtable.h"
#include "cygheap.h"
+#include <wchar.h>
static const char cygnus_class[] = "cygnus";
reg_key::reg_key (HKEY top, REGSAM access, ...): _disposition (0)
key_is_invalid = 1;
}
-char *
-get_registry_hive_path (const char *name, char *path)
+PWCHAR
+get_registry_hive_path (const PWCHAR name, PWCHAR path)
{
- char key[256];
+ WCHAR key[256], *kend;
HKEY hkey;
if (!name || !path)
return NULL;
- __small_sprintf (key, "SOFTWARE\\Microsoft\\WindowsNT\\CurrentVersion\\"
- "ProfileList\\%s", name);
- if (!RegOpenKeyExA (HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &hkey))
+ kend = wcpcpy (key, L"SOFTWARE\\Microsoft\\WindowsNT\\CurrentVersion\\ProfileList\\");
+ wcpcpy (kend, name);
+ if (!RegOpenKeyExW (HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &hkey))
{
- char buf[PATH_MAX];
+ WCHAR buf[NT_MAX_PATH];
+ WCHAR tmp[NT_MAX_PATH];
DWORD type, siz;
- path[0] = '\0';
- if (!RegQueryValueExA (hkey, "ProfileImagePath", 0, &type,
+ path[0] = L'\0';
+ if (!RegQueryValueExW (hkey, L"ProfileImagePath", 0, &type,
(BYTE *)buf, (siz = sizeof (buf), &siz)))
- ExpandEnvironmentStringsA (buf, path, PATH_MAX);
+ ExpandEnvironmentStringsW (buf, path, NT_MAX_PATH);
RegCloseKey (hkey);
if (path[0])
return path;
}
- debug_printf ("HKLM\\%s not found", key);
+ debug_printf ("HKLM\\%W not found", key);
return NULL;
}
void
-load_registry_hive (const char * name)
+load_registry_hive (const PWCHAR name)
{
- char path[PATH_MAX];
+ WCHAR path[NT_MAX_PATH];
HKEY hkey;
LONG ret;
if (!name)
return;
/* Check if user hive is already loaded. */
- if (!RegOpenKeyExA (HKEY_USERS, name, 0, KEY_READ, &hkey))
+ if (!RegOpenKeyExW (HKEY_USERS, name, 0, KEY_READ, &hkey))
{
- debug_printf ("User registry hive for %s already exists", name);
+ debug_printf ("User registry hive for %W already exists", name);
RegCloseKey (hkey);
return;
}
if (get_registry_hive_path (name, path))
{
- strcat (path, "\\NTUSER.DAT");
- if ((ret = RegLoadKeyA (HKEY_USERS, name, path)) != ERROR_SUCCESS)
- debug_printf ("Loading user registry hive for %s failed: %d", name, ret);
+ wcscat (path, L"\\NTUSER.DAT");
+ if ((ret = RegLoadKeyW (HKEY_USERS, name, path)) != ERROR_SUCCESS)
+ debug_printf ("Loading user registry hive for %W failed: %d", name, ret);
}
}
};
/* Evaluates path to the directory of the local user registry hive */
-char *__stdcall get_registry_hive_path (const char *name, char *path);
-void __stdcall load_registry_hive (const char *name);
+PWCHAR __stdcall get_registry_hive_path (const PWCHAR name, PWCHAR path);
+void __stdcall load_registry_hive (const PWCHAR name);
return id;
}
+PWCHAR
+cygpsid::string (PWCHAR nsidstr) const
+{
+ UNICODE_STRING sid;
+
+ if (!psid || !nsidstr)
+ return NULL;
+ RtlInitEmptyUnicodeString (&sid, nsidstr, 256);
+ RtlConvertSidToUnicodeString (&sid, psid, FALSE);
+ return nsidstr;
+}
char *
cygpsid::string (char *nsidstr) const
int get_uid () { return get_id (FALSE); }
int get_gid () { return get_id (TRUE); }
+ PWCHAR string (PWCHAR nsidstr) const;
char *string (char *nsidstr) const;
bool operator== (const PSID nsid) const
extern "C" int
__small_vsprintf (char *dst, const char *fmt, va_list ap)
{
- char tmp[PATH_MAX];
+ char tmp[NT_MAX_PATH];
char *orig = dst;
const char *s;
PWCHAR w;
dst = rnargLL (dst, 16, 0, len, pad);
break;
case 'P':
- if (!GetModuleFileName (NULL, tmp, PATH_MAX))
+ if (!GetModuleFileName (NULL, tmp, NT_MAX_PATH))
s = "cygwin program";
else
s = tmp;
pn = NULL;
char *p;
- char progname[PATH_MAX];
+ char progname[NT_MAX_PATH];
if (!pn)
GetModuleFileName (NULL, pn = progname, sizeof (progname));
if (!pn)
if (new_token != hProcToken)
{
/* Avoid having HKCU use default user */
- char name[128];
+ WCHAR name[128];
load_registry_hive (usersid.string (name));
/* Try setting owner to same value as user. */
if (test_uid (puserprof, name, namelen))
return puserprof;
- char userprofile_env_buf[PATH_MAX];
- char win_id[UNLEN + 1]; /* Large enough for SID */
+ WCHAR userprofile_env_buf[NT_MAX_PATH];
+ WCHAR win_id[UNLEN + 1]; /* Large enough for SID */
cfree_and_set (puserprof, almost_null);
if (get_registry_hive_path (get_windows_id (win_id), userprofile_env_buf))
- puserprof = cstrdup (userprofile_env_buf);
+ sys_wcstombs_alloc (&puserprof, HEAP_STR, userprofile_env_buf);
return puserprof;
}
/* Note that MAX_PATH is defined in the windows headers */
/* There is also PATH_MAX and MAXPATHLEN.
- PATH_MAX is from Posix and does *not* include the trailing NUL.
+ PATH_MAX is from Posix and does include the trailing NUL.
MAXPATHLEN is from Unix.
Thou shalt use CYG_MAX_PATH throughout. It avoids the NUL vs no-NUL
#define CYG_MAX_PATH (MAX_PATH)
+/* There's no define for the maximum path length the NT kernel can handle.
+ That's why we define our own to use in path length test and for path
+ buffer sizes. As MAX_PATH and PATH_MAX, this is defined including the
+ trailing 0. Internal buffers and internal path routines should use
+ NT_MAX_PATH. PATH_MAX as defined in limits.h is the maximum length of
+ application provided path strings we handle. */
+/* FIXME: The name is preliminary and TBD. */
+#define NT_MAX_PATH 32768
+
#ifdef __cplusplus
extern const char case_folded_lower[];