delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/11/06/01:12:04

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <436D9E6C.70907@cwilson.no.fastmail.spam.com>
Date: Sun, 06 Nov 2005 01:10:52 -0500
From: Charles Wilson <news AT cwilson DOT no DOT fastmail DOT spam DOT com>
User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)
MIME-Version: 1.0
To: Charles Wilson <cygwin AT cwilson DOT fastmail DOT fm>, cygwin AT cygwin DOT com
Subject: Re: BUG: alternatives
References: <436CF5E9 DOT 30106 AT cwilson DOT fastmail DOT fm> <001201c5e244$c9e50490$020aa8c0 AT DFW5RB41> <436D9993 DOT 7050100 AT cwilson DOT fastmail DOT fm>
In-Reply-To: <436D9993.7050100@cwilson.fastmail.fm>

--------------030607090207010104070501
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

The following seems to do the trick, at least on my (binmount) system 
with dos-ified /var/lib/alternatives/* files.

I don't think I'm doing anything obviously stupid here, but see attached 
patch.  If it looks okay, I'll put out a 'testing' release of 
alternatives shortly.

--
Chuck

--------------030607090207010104070501
Content-Type: text/plain;
 name="alternatives-textmode.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="alternatives-textmode.patch"

diff -urN -x .build -x .inst -x .sinst -x .gmo -x .mo alternatives-1.3.20a-orig/alternatives.c alternatives-1.3.20a/alternatives.c
--- alternatives-1.3.20a-orig/alternatives.c	2005-06-25 21:55:02.000000000 -0400
+++ alternatives-1.3.20a/alternatives.c	2005-11-06 01:01:06.718750000 -0500
@@ -16,6 +16,15 @@
 
 #define	FLAGS_TEST	(1 << 0)
 #define	FLAGS_VERBOSE	(1 << 1)
+#if defined(O_BINARY)
+# define _O_BINARY		O_BINARY
+# define FOPEN_WRITE_MODE	"wb"
+# define FOPEN_READ_MODE	"rb"
+#else
+# define _O_BINARY		0
+# define FOPEN_WRITE_MODE	"w"
+# define FOPEN_READ_MODE	"r"
+#endif
 
 #define FL_TEST(flags)	    ((flags) & FLAGS_TEST)
 #define FL_VERBOSE(flags)   ((flags) & FLAGS_VERBOSE)
@@ -115,16 +124,30 @@
 
 char * parseLine(char ** buf) {
     char * start = *buf;
-    char * end;
+    char * end1 = *buf;
+    char * end2;
 
     if (!*buf || !**buf) return NULL;
 
-    end = strchr(start, '\n');
-    if (!end) {
-	*buf = start + strlen(start);
-    } else {
-	*buf = end + 1;
-	*end = '\0';
+    while (*end1 && (*end1 != '\n') && (*end1 != '\r'))
+       end1++;
+
+    end2 = end1;
+    while (*end2 && (*end2 == '\r')) /* only walk past '\r', NOT '\n' */
+    {
+       *end2 = '\0';
+       end2++;
+    }
+
+    /* ensures this parseLine() only consumes ONE '\n' */
+    if (*end2 == '\n')
+    {
+       *buf = end2 + 1;
+       *end2 = '\0';
+    }
+    else
+    {
+       *buf = end2;
     }
 
     while (isspace(*start) && *start) start++;
@@ -160,7 +183,7 @@
     if (FL_VERBOSE(flags))
 	printf(_("reading %s\n"), path);
 
-    if ((fd = open(path, O_RDONLY)) < 0) {
+    if ((fd = open(path, O_RDONLY | _O_BINARY)) < 0) {
 	if (errno == ENOENT) return 3;
 	fprintf(stderr, _("failed to open %s: %s\n"), path,
 	        strerror(errno));
@@ -414,7 +437,7 @@
     if (FL_TEST(flags))
 	fd = dup(1);
     else
-	fd = open(path, O_RDWR | O_CREAT | O_EXCL, 0644);
+	fd = open(path, O_RDWR | O_CREAT | O_EXCL | _O_BINARY, 0644);
 
     if (fd < 0) {
 	if (errno == EEXIST) 
@@ -425,7 +448,7 @@
 	return 1;
     }
 
-    f = fdopen(fd, "w");
+    f = fdopen(fd, FOPEN_WRITE_MODE); 
     fprintf(f, "%s\n", set->mode == AUTO ? "auto" : "manual");
     fprintf(f, "%s\n", set->alts[0].master.facility);
     for (i = 0; i < set->alts[0].numSlaves; i++) {


--------------030607090207010104070501
Content-Type: text/plain; charset=us-ascii

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/
--------------030607090207010104070501--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019