CVS update: /ccvs/windows-NT/

[email protected] 31 May 2005 07:13:33 -0000
Newsgroups gmane.comp.version-control.cvs.cvs
Message-ID <[email protected]>
User: conradpino
Date: 05/05/31 00:13:33

Modified:
 /ccvs/windows-NT/
  ChangeLog, filesubr.c, pwd.c, unistd.c, unistd.h, woe32.c, woe32.h

Log:
 * unistd.c, unistd.c: Add new "usleep" function using "my_usleep"
   logic taken from "woe32.c" file.
 * woe32.c, woe32.h: Add new (woe32_home_dir,woe32_shell) functions.
 * woe32.c: Modify "woe32_nanosleep" to use "unistd.h" "usleep".
 * filesubr.c: Modify "get_homedir" to use "woe32_home_dir".
 * pwd.c: Modify "getpwuid" to use "woe32_home_dir" & "woe32_shell".
   Append "USERNAME" to "login_strings" array.

File Changes:

Directory: /ccvs/windows-NT/
============================

File [changed]: ChangeLog
Url: https://ccvs.cvshome.org/source/browse/ccvs/windows-NT/ChangeLog?r1=1.313&r2=1.314
Delta lines:  +11 -0
--------------------
--- ChangeLog	31 May 2005 06:39:59 -0000	1.313
+++ ChangeLog	31 May 2005 07:13:31 -0000	1.314
@@ -1,3 +1,14 @@
+2005-05-31  Conrad T. Pino  <[email protected]>
+
+	* unistd.c, unistd.c: Add new "usleep" function using "my_usleep"
+	  logic taken from "woe32.c" file.
+	* woe32.c, woe32.h: Add new (woe32_home_dir,woe32_shell) functions.
+	* woe32.c: Modify "woe32_nanosleep" to use "unistd.h" "usleep".
+	* filesubr.c: Modify "get_homedir" to use "woe32_home_dir".
+	* pwd.c: Modify "getpwuid" to use "woe32_home_dir" & "woe32_shell".
+	  Append "USERNAME" to "login_strings" array.
+
+
 2005-05-30  Conrad T. Pino  <[email protected]>
 
 	* woe32.c, woe32.h: Move functions into alpabetical order.

File [changed]: filesubr.c
Url: https://ccvs.cvshome.org/source/browse/ccvs/windows-NT/filesubr.c?r1=1.57&r2=1.58
Delta lines:  +7 -16
--------------------
--- filesubr.c	26 May 2005 09:40:40 -0000	1.57
+++ filesubr.c	31 May 2005 07:13:31 -0000	1.58
@@ -764,25 +764,16 @@
    said to be set to c:\users\default by default.  */
 
 char *
-get_homedir ()
+get_homedir (void)
 {
-    static char *pathbuf;
-    char *hd, *hp;
+    char *homedir;
 
-    if (pathbuf != NULL)
-	return pathbuf;
-    else if ((hd = getenv ("HOME")))
-	return hd;
-    else if ((hd = getenv ("HOMEDRIVE")) && (hp = getenv ("HOMEPATH")))
-    {
-	pathbuf = xmalloc (strlen (hd) + strlen (hp) + 5);
-	strcpy (pathbuf, hd);
-	strcat (pathbuf, hp);
+    homedir = getenv ("HOME");
 
-	return pathbuf;
-    }
-    else
-	return NULL;
+    if (homedir == NULL)
+	homedir = woe32_home_dir ();
+
+    return homedir;
 }
 
 /* Compose a path to a file in the home directory.  This is necessary because

File [changed]: pwd.c
Url: https://ccvs.cvshome.org/source/browse/ccvs/windows-NT/pwd.c?r1=1.10&r2=1.11
Delta lines:  +3 -6
-------------------
--- pwd.c	31 May 2005 02:08:26 -0000	1.10
+++ pwd.c	31 May 2005 07:13:31 -0000	1.11
@@ -31,7 +31,7 @@
 
 static char *login_strings[] =
 {
-  "LOGIN", "USER", "MAILNAME", NULL
+  "LOGIN", "USER", "MAILNAME", "USERNAME", NULL
 };
 
 static char *group_strings[] =
@@ -42,9 +42,6 @@
 
 static char *anonymous = "anonymous";	/* if all else fails ... */
 
-static char *home_dir = ".";	/* we feel (no|every)where at home */
-static char *login_shell = "not command.com!";
-
 static char *login = NULL;/* cache the names here	*/
 static char *group = NULL;
 
@@ -56,8 +53,8 @@
 getpwuid (int uid)
 {
   pw.pw_name = getlogin ();
-  pw.pw_dir = home_dir;
-  pw.pw_shell = login_shell;
+  pw.pw_dir = woe32_home_dir ();
+  pw.pw_shell = woe32_shell ();
   pw.pw_uid = 0;
 
   return &pw;

File [changed]: unistd.c
Url: https://ccvs.cvshome.org/source/browse/ccvs/windows-NT/unistd.c?r1=1.1&r2=1.2
Delta lines:  +22 -3
--------------------
--- unistd.c	31 May 2005 04:13:19 -0000	1.1
+++ unistd.c	31 May 2005 07:13:31 -0000	1.2
@@ -10,7 +10,7 @@
 #include <conio.h>
 
 #define WIN32_LEAN_AND_MEAN
-#include <windows.h>
+#include <winsock.h>  /* This does: #include <windows.h> */
 
 /* Please order functions by name if possible */
 
@@ -48,6 +48,25 @@
 
 unsigned int sleep (unsigned seconds)
 {
-	Sleep(1000*seconds);
+    Sleep (1000*seconds);
+    return 0;
+}
+
+
+
+/*
+ * Sleep at least some number of microseconds
+ */
+int usleep (useconds_t microseconds)
+{
+    if ( microseconds )
+    {
+	const useconds_t one_second = 1000000;
+	struct timeval tv_delay;
+
+	tv_delay.tv_sec = microseconds / one_second;
+	tv_delay.tv_usec = microseconds % one_second;
+	return select (0, NULL, NULL, NULL, &tv_delay);
+    }
 	return 0;
 }

File [changed]: unistd.h
Url: https://ccvs.cvshome.org/source/browse/ccvs/windows-NT/unistd.h?r1=1.6&r2=1.7
Delta lines:  +3 -0
-------------------
--- unistd.h	31 May 2005 02:08:26 -0000	1.6
+++ unistd.h	31 May 2005 07:13:31 -0000	1.7
@@ -31,11 +31,14 @@
 #define pid_t int
 #endif /* pid_t */
 
+typedef unsigned long useconds_t;
+
 /* These functions doesn't exist under Windows NT; we provide stubs */
 char * getpass (const char *prompt);
 pid_t getpid (void);
 int readlink (const char *path, char *buf, size_t buf_size);
 unsigned int sleep (unsigned int seconds);
+int usleep (useconds_t microseconds);
 
 /*
 FIXME:	gethostname prototype for lib/xgethostname.c, no #include <winsock.h>

File [changed]: woe32.c
Url: https://ccvs.cvshome.org/source/browse/ccvs/windows-NT/woe32.c?r1=1.8&r2=1.9
Delta lines:  +63 -13
---------------------
--- woe32.c	31 May 2005 06:39:59 -0000	1.8
+++ woe32.c	31 May 2005 07:13:31 -0000	1.9
@@ -15,6 +15,8 @@
 #include <winsock.h>  /* This does: #include <windows.h> */
 
 #include <stdlib.h>
+#include <unistd.h>
+#include <xalloc.h>
 
 
 
@@ -69,18 +71,33 @@
 
 
 
-/*
- * Sleep at least some number of microseconds, specified with nanosecond
- * resolution and rounding up to the nearest microsecond.
- */
-static int
-my_usleep (const struct timespec *ts_delay)
-{
-    struct timeval tv_delay;
-    tv_delay.tv_sec = ts_delay->tv_sec;
-    tv_delay.tv_usec = ts_delay->tv_nsec / 1000
-		       + (ts_delay->tv_nsec % 1000 ? 1 : 0);
-    return select (0, (void *) 0, (void *) 0, (void *) 0, &tv_delay);
+char *
+woe32_home_dir (void)
+{
+    static char *home_dir = NULL;
+    char *home_drive, *home_path;
+
+    if (home_dir)
+	return home_dir;
+    
+    if ((home_drive = getenv ("HOMEDRIVE")) && (home_path = getenv ("HOMEPATH")))
+    {
+	const char NUL = '\0';
+	size_t home_drive_len, home_path_len;
+
+	home_drive_len = strlen (home_drive);
+	home_path_len  = strlen (home_path);
+
+	home_dir = xmalloc (home_drive_len + home_path_len + sizeof NUL);
+
+	memcpy (home_dir,                  home_drive, home_drive_len );
+	memcpy (home_dir + home_drive_len, home_path,  home_path_len  );
+	home_dir[ home_drive_len + home_path_len ] = NUL;
+
+	return home_dir;
+    }
+
+    return NULL;
 }
 
 
@@ -90,5 +107,38 @@
 woe32_nanosleep (const struct timespec *requested_delay,
                        struct timespec *remaining_delay)
 {
-    return my_usleep (requested_delay);
+    const useconds_t one_second = 1000000;
+    const useconds_t nano_per_micro = 1000;
+    useconds_t micro_delay;
+
+    micro_delay = requested_delay->tv_sec * one_second
+		+ ( requested_delay->tv_nsec + nano_per_micro - 1 ) / nano_per_micro
+		;
+
+    return usleep (micro_delay);
+}
+
+
+
+char *
+woe32_shell (void)
+{
+    char *shell;
+
+    shell = getenv ("ComSpec");
+
+    if (shell == NULL)
+    {
+	/* Windows always sets ComSpec, the user is messing with us */
+	const char *os;
+
+	if ((os = getenv ("OS")) && strcmp (os, "Windows_NT"))
+	    /* Windows NT, Windows 2000, Windows XP, Windows 2003 */
+	    shell = "cmd.exe";
+	else
+	    /* Windows 95, Windows 98, Windows Me */
+	    shell = "command.com";
+    }
+
+    return shell;
 }

File [changed]: woe32.h
Url: https://ccvs.cvshome.org/source/browse/ccvs/windows-NT/woe32.h?r1=1.2&r2=1.3
Delta lines:  +4 -0
-------------------
--- woe32.h	31 May 2005 06:39:59 -0000	1.2
+++ woe32.h	31 May 2005 07:13:31 -0000	1.3
@@ -14,6 +14,8 @@
 
 char *woe32_getlogin (void);
 
+char *woe32_home_dir (void);
+
 /* #define SYSTEM_INITIALIZE(pargc,pargv) woe32_init_winsock() */
 void woe32_init_winsock (void);
 
@@ -21,4 +23,6 @@
 int woe32_nanosleep (const struct timespec *requested_delay,
                            struct timespec *remaining_delay);
 
+char * woe32_shell (void);
+
 #endif /* WOE32_H */