OSDN Git Service

* fhandler.h (fhandler_base): Remove obsolete _rpos and _rsize elements.
authorcgf <cgf>
Sat, 7 Oct 2000 18:12:11 +0000 (18:12 +0000)
committercgf <cgf>
Sat, 7 Oct 2000 18:12:11 +0000 (18:12 +0000)
* fhandler.cc (fhandler_base::open): Ditto.
* fhandler.cc (fhandler_base::fhandler_base): Ditto.
(fhandler_base::read): Ditto.  Add more debugging output.  Don't issue a \r
when \r\n detected.
* pipe.cc (make_pipe): Streamline slightly.  Make debug output more
interesting.
* strace.cc (strace::vsprintf): Use __progname where appropriate to distinguish
strace output when exec'ing.

winsup/cygwin/ChangeLog
winsup/cygwin/fhandler.cc
winsup/cygwin/fhandler.h
winsup/cygwin/pipe.cc
winsup/cygwin/strace.cc

index f00bf5b..7f39296 100644 (file)
@@ -1,3 +1,16 @@
+Sat Oct  7 13:59:15 2000  Christopher Faylor <cgf@cygnus.com>
+
+       * fhandler.h (fhandler_base): Remove obsolete _rpos and _rsize
+       elements.
+       * fhandler.cc (fhandler_base::open): Ditto.
+       * fhandler.cc (fhandler_base::fhandler_base): Ditto.
+       (fhandler_base::read): Ditto.  Add more debugging output.  Don't issue
+       a \r when \r\n detected.
+       * pipe.cc (make_pipe): Streamline slightly.  Make debug output more
+       interesting.
+       * strace.cc (strace::vsprintf): Use __progname where appropriate to
+       distinguish strace output when exec'ing.
+
 Sat Oct  7 19:25:00 2000  Corinna Vinschen <corinna@vinschen.de>
 
        * fhandler.h (fhandler_dev_mem): Add methods mmap, munmap and msync.
 Sat Oct  7 19:25:00 2000  Corinna Vinschen <corinna@vinschen.de>
 
        * fhandler.h (fhandler_dev_mem): Add methods mmap, munmap and msync.
@@ -102,12 +115,12 @@ Mon Oct  2 15:15:01 2000  Christopher Faylor <cgf@cygnus.com>
 
 Mon Oct  2 11:05:00 2000  Corinna Vinschen <corinna@vinschen.de>
 
 
 Mon Oct  2 11:05:00 2000  Corinna Vinschen <corinna@vinschen.de>
 
-        * fhandler_mem.cc: Load ntdll functions via autoload method.
-        (load_ntdll_funcs): Eliminated.
+       * fhandler_mem.cc: Load ntdll functions via autoload method.
+       (load_ntdll_funcs): Eliminated.
 
 Sun Oct  1 16:36:00 2000  Corinna Vinschen <corinna@vinschen.de>
 
 
 Sun Oct  1 16:36:00 2000  Corinna Vinschen <corinna@vinschen.de>
 
-        * fhandler_mem.cc (load_ntdll_funcs): Add missing __stdcall qualifiers.
+       * fhandler_mem.cc (load_ntdll_funcs): Add missing __stdcall qualifiers.
 
 Sun Oct  1 22:20:39 2000  Christopher Faylor <cgf@cygnus.com>
 
 
 Sun Oct  1 22:20:39 2000  Christopher Faylor <cgf@cygnus.com>
 
@@ -125,7 +138,7 @@ Sun Oct  1  2:56:00 2000  Corinna Vinschen <corinna@vinschen.de>
 
        * Makefile.in: Add fhandler_mem.o to the dependencies.
        * dtable.cc (dtable::build_fhandler): Add case for FH_MEM.
 
        * Makefile.in: Add fhandler_mem.o to the dependencies.
        * dtable.cc (dtable::build_fhandler): Add case for FH_MEM.
-       * fhandler.h: Add FH_MEM device type.  Add class fhandler_dev_mem. 
+       * fhandler.h: Add FH_MEM device type.  Add class fhandler_dev_mem.
        * fhandler_mem.cc: New file. Implementation of class fhandler_dev_mem.
        * path.cc: Add /dev/mem to windows_device_names.
        (get_device_number): Add FH_MEM type.
        * fhandler_mem.cc: New file. Implementation of class fhandler_dev_mem.
        * path.cc: Add /dev/mem to windows_device_names.
        (get_device_number): Add FH_MEM type.
index 7307e88..20b2c2a 100644 (file)
@@ -364,8 +364,6 @@ fhandler_base::open (int flags, mode_t mode)
 
   namehash_ = hash_path_name (0, get_win32_name ());
   set_io_handle (x);
 
   namehash_ = hash_path_name (0, get_win32_name ());
   set_io_handle (x);
-  rpos_ = 0;
-  rsize_ = -1;
   int bin;
   int fmode;
   if ((bin = flags & (O_BINARY | O_TEXT)))
   int bin;
   int fmode;
   if ((bin = flags & (O_BINARY | O_TEXT)))
@@ -441,8 +439,13 @@ fhandler_base::read (void *in_ptr, size_t in_len)
        copied_chars += readlen;
     }
 
        copied_chars += readlen;
     }
 
-  if (copied_chars <= 0 || get_r_binary ())
+  if (copied_chars <= 0)
     return copied_chars;
     return copied_chars;
+  if (get_r_binary ())
+    {
+      debug_printf ("returning %d chars, binary mode", copied_chars);
+      return copied_chars;
+    }
 
   /* Scan buffer for a control-z and shorten the buffer to that length */
 
 
   /* Scan buffer for a control-z and shorten the buffer to that length */
 
@@ -454,7 +457,10 @@ fhandler_base::read (void *in_ptr, size_t in_len)
     }
 
   if (copied_chars == 0)
     }
 
   if (copied_chars == 0)
-    return 0;
+    {
+      debug_printf ("returning 0 chars, text mode, CTRL-Z found");
+      return 0;
+    }
 
   /* Scan buffer and turn \r\n into \n */
   register char *src= (char *) ptr;
 
   /* Scan buffer and turn \r\n into \n */
   register char *src= (char *) ptr;
@@ -487,8 +493,6 @@ fhandler_base::read (void *in_ptr, size_t in_len)
   *dst++ = c;
   copied_chars = dst - (char *) ptr;
 
   *dst++ = c;
   copied_chars = dst - (char *) ptr;
 
-  rpos_ += copied_chars;
-
 #ifndef NOSTRACE
   if (strace.active)
     {
 #ifndef NOSTRACE
   if (strace.active)
     {
@@ -507,6 +511,7 @@ fhandler_base::read (void *in_ptr, size_t in_len)
     }
 #endif
 
     }
 #endif
 
+  debug_printf ("returning %d chars, text mode", copied_chars);
   return copied_chars;
 }
 
   return copied_chars;
 }
 
@@ -564,118 +569,63 @@ fhandler_base::write (const void *ptr, size_t len)
 
   if (get_w_binary ())
     {
 
   if (get_w_binary ())
     {
+      debug_printf ("binary write");
       res = raw_write (ptr, len);
     }
   else
     {
       res = raw_write (ptr, len);
     }
   else
     {
-#ifdef NOTDEF
-      /* Keep track of previous \rs, we don't want to turn existing
-        \r\n's into \r\n\n's */
-      register int pr = 0;
-
-      /* Copy things in chunks */
-      char buf[CHUNK_SIZE];
-
-      for (unsigned int i = 0; i < len; i += sizeof (buf) / 2)
-       {
-         register const char *src = (char *)ptr + i;
-         int todo;
-         if ((todo = len - i) > sizeof (buf) / 2)
-           todo = sizeof (buf) / 2;
-         register const char *end = src + todo;
-         register char *dst = buf;
-         while (src < end)
-           {
-             if (*src == '\n' && !pr)
-               {
-                 /* Emit a cr lf here */
-                 *dst ++ = '\r';
-                 *dst ++ = '\n';
-               }
-             else if (*src == '\r')
-               {
-                 *dst ++ = '\r';
-                 pr = 1;
-               }
-             else
-               {
-                 *dst ++ = *src;
-                 pr = 0;
-               }
-             src++;
-           }
-         int want = dst - buf;
-         if ((res = raw_write (buf, want)) != want)
-           {
-             if (res == -1)
-               return -1;
-             /* FIXME: */
-             /* Tricky... Didn't write everything we wanted.. How can
-                we work out exactly which chars were sent?  We don't...
-                This will only happen in pretty nasty circumstances. */
-             rpos_ += i;
-             return i;
-           }
-       }
-#else
+      debug_printf ("text write");
       /* This is the Microsoft/DJGPP way.  Still not ideal, but it's
       /* This is the Microsoft/DJGPP way.  Still not ideal, but it's
-        compatible. */
+        compatible.
+        Modified slightly by CGF 2000-10-07 */
 
       int left_in_data = len;
       char *data = (char *)ptr;
 
       int left_in_data = len;
       char *data = (char *)ptr;
+      res = 0;
 
       while (left_in_data > 0)
        {
 
       while (left_in_data > 0)
        {
-         char buf[CHUNK_SIZE], *buf_ptr = buf;
+         char buf[CHUNK_SIZE + 1], *buf_ptr = buf;
          int left_in_buf = CHUNK_SIZE;
 
          while (left_in_buf > 0 && left_in_data > 0)
            {
          int left_in_buf = CHUNK_SIZE;
 
          while (left_in_buf > 0 && left_in_data > 0)
            {
-             if (*data == '\n')
+             char ch = *data++;
+             if (ch == '\n')
                {
                {
-                 if (left_in_buf == 1)
-                   {
-                     /* Not enough room for \r and \n */
-                     break;
-                   }
                  *buf_ptr++ = '\r';
                  left_in_buf--;
                }
                  *buf_ptr++ = '\r';
                  left_in_buf--;
                }
-             *buf_ptr++ = *data++;
+             *buf_ptr++ = ch;
              left_in_buf--;
              left_in_data--;
              left_in_buf--;
              left_in_data--;
+             if (left_in_data > 0 && ch == '\r' && *data == '\n')
+               {
+                 *buf_ptr++ = *data++;
+                 left_in_buf--;
+                 left_in_data--;
+               }
            }
 
          /* We've got a buffer-full, or we're out of data.  Write it out */
            }
 
          /* We've got a buffer-full, or we're out of data.  Write it out */
+         int nbytes;
          int want = buf_ptr - buf;
          int want = buf_ptr - buf;
-         if ((res = raw_write (buf, want)) != want)
+         if ((nbytes = raw_write (buf, want)) == want)
            {
            {
-             if (res == -1)
-               return -1;
-             /* FIXME: */
-             /* Tricky... Didn't write everything we wanted.. How can
-                we work out exactly which chars were sent?  We don't...
-                This will only happen in pretty nasty circumstances. */
-             int i = (len-left_in_data) - left_in_buf;
-             rpos_ += i;
-             /* just in case the math is off, guarantee it looks like
-                a disk full error */
-             if (i >= (int)len)
-               i = len-1;
-             if (i < 0)
-               i = 0;
-             return i;
+             /* Keep track of how much written not counting additional \r's */
+             res = data - (char *)ptr;
+             continue;
            }
            }
-       }
-#endif
 
 
-      /* Done everything, update by the chars that the user sent */
-      rpos_ += len;
-      /* Length of file has changed */
-      rsize_ = -1;
-      res = len;
-      debug_printf ("after write, name %s, rpos %d", unix_path_name_, rpos_);
+         if (nbytes == -1)
+           res = -1;           /* Error */
+         else
+           res += nbytes;      /* Partial write.  Return total bytes written. */
+         break;                /* All done */
+       }
     }
     }
+
+  debug_printf ("%d = write (%p, %d)", res, ptr, len);
   return res;
 }
 
   return res;
 }
 
@@ -1125,8 +1075,6 @@ fhandler_base::operator delete (void *p)
 fhandler_base::fhandler_base (DWORD devtype, const char *name, int unit):
   access_ (0),
   io_handle (NULL),
 fhandler_base::fhandler_base (DWORD devtype, const char *name, int unit):
   access_ (0),
   io_handle (NULL),
-  rpos_ (0),
-  rsize_ (0),
   namehash_ (0),
   openflags_ (0),
   rabuf (NULL),
   namehash_ (0),
   openflags_ (0),
   rabuf (NULL),
index 3f8a1c1..c869067 100644 (file)
@@ -129,9 +129,6 @@ private:
   int access_;
   HANDLE io_handle;
 
   int access_;
   HANDLE io_handle;
 
-  int rpos_; /* Used in text reading */
-  int rsize_;
-
   unsigned long namehash_;     /* hashed filename, used as inode num */
 
   /* Full unix path name of this file */
   unsigned long namehash_;     /* hashed filename, used as inode num */
 
   /* Full unix path name of this file */
index 2de4991..4a6e493 100644 (file)
@@ -24,8 +24,9 @@ make_pipe (int fildes[2], unsigned int psize, int mode)
   SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK," make_pipe");
 
   HANDLE r, w;
   SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK," make_pipe");
 
   HANDLE r, w;
-  int  fdr, fdw;
+  int  fdr = -1, fdw = -1;
   SECURITY_ATTRIBUTES *sa = (mode & O_NOINHERIT) ?  &sec_none_nih : &sec_none;
   SECURITY_ATTRIBUTES *sa = (mode & O_NOINHERIT) ?  &sec_none_nih : &sec_none;
+  int res = -1;
 
   if ((fdr = fdtab.find_unused_handle ()) < 0)
     set_errno (ENMFILE);
 
   if ((fdr = fdtab.find_unused_handle ()) < 0)
     set_errno (ENMFILE);
@@ -50,16 +51,12 @@ make_pipe (int fildes[2], unsigned int psize, int mode)
       fildes[0] = fdr;
       fildes[1] = fdw;
 
       fildes[0] = fdr;
       fildes[1] = fdw;
 
-      debug_printf ("0 = pipe (%p) (%d:%p, %d:%p)", fildes,
-                   fdr, fhr->get_handle (), fdw, fhw->get_handle ());
-
-      ReleaseResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK," make_pipe");
-      return 0;
+      res = 0;
     }
 
     }
 
-  syscall_printf ("-1 = pipe (%p)", fildes);
+  syscall_printf ("%d = make_pipe ([%d, %d], %d, %p)", res, fdr, fdw, psize, mode);
   ReleaseResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK," make_pipe");
   ReleaseResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK," make_pipe");
-  return -1;
+  return res;
 }
 
 extern "C" int
 }
 
 extern "C" int
index 60d81e0..92494a4 100644 (file)
@@ -96,6 +96,8 @@ getfunc (char *in_dst, const char *func)
   return dst - in_dst;
 }
 
   return dst - in_dst;
 }
 
+extern "C" char *__progname;
+
 /* sprintf analog for use by output routines. */
 int
 strace::vsprntf (char *buf, const char *func, const char *infmt, va_list ap)
 /* sprintf analog for use by output routines. */
 int
 strace::vsprntf (char *buf, const char *func, const char *infmt, va_list ap)
@@ -105,6 +107,7 @@ strace::vsprntf (char *buf, const char *func, const char *infmt, va_list ap)
   static int nonewline = FALSE;
   DWORD err = GetLastError ();
   const char *tn = threadname (0);
   static int nonewline = FALSE;
   DWORD err = GetLastError ();
   const char *tn = threadname (0);
+  char *pn = __progname ?: myself->progname;
 
   int microsec = microseconds ();
   lmicrosec = microsec;
 
   int microsec = microseconds ();
   lmicrosec = microsec;
@@ -117,11 +120,13 @@ strace::vsprntf (char *buf, const char *func, const char *infmt, va_list ap)
     count = 0;
   else
     {
     count = 0;
   else
     {
-      char *p, progname[sizeof (myself->progname)];
-      if ((p = strrchr (myself->progname, '\\')) != NULL)
+      char *p, progname[MAX_PATH + 1];
+      if ((p = strrchr (pn, '\\')) != NULL)
+       p++;
+      else if ((p = strrchr (pn, '/')) != NULL)
        p++;
       else
        p++;
       else
-       p = myself->progname;
+       p = pn;
       strcpy (progname, p);
       if ((p = strrchr (progname, '.')) != NULL)
        *p = '\000';
       strcpy (progname, p);
       if ((p = strrchr (progname, '.')) != NULL)
        *p = '\000';