Mail Archives: cygwin/2005/11/06/01:12:04
--------------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 -