X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Fline-reader.c;h=c7d024b44a45706e925e2d45743c6e831f6beb9b;hb=e5a05f16e98783e2785107059de22a44f51c18ea;hp=6f90b502cd856dd64db366ce1bb36561141648f0;hpb=20af4ead4d4c440c5bc269274cd5a87fa9e7056d;p=pspp diff --git a/src/libpspp/line-reader.c b/src/libpspp/line-reader.c index 6f90b502cd..c7d024b44a 100644 --- a/src/libpspp/line-reader.c +++ b/src/libpspp/line-reader.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2010, 2011 Free Software Foundation, Inc. + Copyright (C) 2010, 2011, 2014 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -125,7 +125,7 @@ line_reader_for_fd (const char *encoding, int fd) && !strcmp (r->encoding, "ASCII")) { r->state = S_AUTO; - r->auto_encoding = xstrdup (encoding); + r->auto_encoding = xstrdup_if_nonnull (encoding); } else r->state = r->encoding_info.unit == 1 ? S_UNIBYTE : S_MULTIBYTE; @@ -311,9 +311,9 @@ off_t line_reader_tell (const struct line_reader *r) { off_t pos = lseek (r->fd, 0, SEEK_CUR); - if (pos >= 0) - pos = MAX (0, pos - r->length); - return pos; + return (pos < 0 ? pos + : pos >= r->length ? pos - r->length + : 0); } /* Returns true if end of file has been encountered reading R. */