summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPaolo Bonzini <bonzini@gnu.org>2006-08-07 17:08:37 +0000
committerPaolo Bonzini <bonzini@gnu.org>2008-01-09 16:12:11 +0100
commit3a8e165ab02487c372df217c1989e287625ce0ae (patch)
tree4fbd6691b82c6272248133177e8ca946362e631c /lib
parent3ca529fbe25706387200425b2a99012d6008f26c (diff)
downloadsed-3a8e165ab02487c372df217c1989e287625ce0ae.tar.gz
treat cygwin CR/LF correctly (and by design, not by chance)
2006-08-03 Paolo Bonzini <bonzini@gnu.org> Corinna Vinschen <vinschen@redhat.com> * lib/getline.c (getline): Remove Windows special casing. * lib/utils.c (register_open_file, ck_fdopen): New. (ck_fopen, ck_mkstemp): Use register_open_file. * lib/utils.h (ck_fdopen): New. * sed/execute.c (open_next_file): Reopen stdin. * sed/sed.h (read_mode): New. * sed/sed.c (read_mode): New. (main): Set it on --binary. (usage): Document --binary. * sed/compile.c (get_openfile): Change second argument to char and turn it into a string within the function. Adjust callers. * sed/execute.c (dump_append_queue, open_next_file): Use it as mode for ck_fopen. git-archimport-id: bonzini@gnu.org--2004b/sed--stable--4.1--patch-71
Diffstat (limited to 'lib')
-rw-r--r--lib/getline.c4
-rw-r--r--lib/utils.c73
-rw-r--r--lib/utils.h1
3 files changed, 51 insertions, 27 deletions
diff --git a/lib/getline.c b/lib/getline.c
index defaeda..ef475b4 100644
--- a/lib/getline.c
+++ b/lib/getline.c
@@ -101,10 +101,6 @@ getline (lineptr, n, stream)
/* Return a partial line since we got an error in the middle. */
win:
-#if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) || defined(MSDOS) || defined(__EMX__)
- if (p - 2 >= *lineptr && p[-2] == '\r')
- p[-2] = p[-1], --p;
-#endif
*p = '\0';
return p - *lineptr;
}
diff --git a/lib/utils.c b/lib/utils.c
index 647fd6d..bc08db6 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -126,25 +126,13 @@ utils_fp_name(fp)
return "<unknown>";
}
-/* Panic on failing fopen */
-FILE *
-ck_fopen(name, mode, fail)
+static void
+register_open_file (fp, name, temp)
+ FILE *fp;
const char *name;
- const char *mode;
- bool fail;
+ bool temp;
{
- FILE *fp;
struct open_file *p;
-
- fp = fopen (name, mode);
- if (!fp)
- {
- if (fail)
- panic(_("couldn't open file %s: %s"), name, strerror(errno));
-
- return NULL;
- }
-
for (p=open_files; p; p=p->link)
{
if (fp == p->fp)
@@ -162,6 +150,51 @@ ck_fopen(name, mode, fail)
p->name = ck_strdup(name);
p->fp = fp;
p->temp = false;
+}
+
+/* Panic on failing fopen */
+FILE *
+ck_fopen(name, mode, fail)
+ const char *name;
+ const char *mode;
+ bool fail;
+{
+ FILE *fp;
+
+ fp = fopen (name, mode);
+ if (!fp)
+ {
+ if (fail)
+ panic(_("couldn't open file %s: %s"), name, strerror(errno));
+
+ return NULL;
+ }
+
+ register_open_file (fp, name, false);
+ return fp;
+}
+
+/* Panic on failing fdopen */
+FILE *
+ck_fdopen(fd, name, mode, fail)
+ int fd;
+ const char *name;
+ const char *mode;
+ bool fail;
+{
+ FILE *fp;
+ struct open_file *p;
+
+ fp = fdopen (fd, mode);
+ if (!fp)
+ {
+ if (fail)
+ panic(_("couldn't attach to %s: %s"), name, strerror(errno));
+
+ return NULL;
+ }
+
+ register_open_file (fp, name, false);
return fp;
}
@@ -197,13 +230,7 @@ ck_mkstemp (p_filename, tmpdir, base)
*p_filename = template;
fp = fdopen (fd, "w");
-
- p = MALLOC(1, struct open_file);
- p->name = ck_strdup (template);
- p->fp = fp;
- p->temp = true;
- p->link = open_files;
- open_files = p;
+ register_open_file (fp, template, true);
return fp;
}
diff --git a/lib/utils.h b/lib/utils.h
index ae09864..cef0f6d 100644
--- a/lib/utils.h
+++ b/lib/utils.h
@@ -23,6 +23,7 @@
void panic P_((const char *str, ...));
FILE *ck_fopen P_((const char *name, const char *mode, bool fail));
+FILE *ck_fdopen P_((int fd, const char *name, const char *mode, bool fail));
void ck_fwrite P_((const VOID *ptr, size_t size, size_t nmemb, FILE *stream));
size_t ck_fread P_((VOID *ptr, size_t size, size_t nmemb, FILE *stream));
void ck_fflush P_((FILE *stream));