On Tue, Apr 8, 2008 at 12:09 AM, Karel Zak <kzak@xxxxxxxxxx> wrote: > What about: > > login-utils/islocal.c | 13 ++++++++----- > 1 files changed, 8 insertions(+), 5 deletions(-) > > > diff --git a/login-utils/islocal.c b/login-utils/islocal.c > index 2976980..7fa1434 100644 > > --- a/login-utils/islocal.c > +++ b/login-utils/islocal.c > @@ -24,13 +24,11 @@ > > #include "pathnames.h" > #include "islocal.h" > > -#define MAX_LENGTH 1024 > > - > int > is_local(char *user) > { > > FILE *fd; > - char line[MAX_LENGTH]; > + char *line; > > int local = 0; > size_t len; > > @@ -40,12 +38,17 @@ is_local(char *user) > > } > > len = strlen(user); > - while(fgets(line, MAX_LENGTH, fd)) { > - if(!strncmp(line, user, len) && line[len] == ':') { > + line = malloc(len + 2); /* 2 = ":\0" */ > + > + while(fgets(line, len + 2, fd)) { > + int c = line[len]; > + if(!strncmp(line, user, len) && c == ':') { Better to reverse that test, I would say. > local = 1; > break; > } > + while(c != '\n' && (c = fgetc(fd)) != EOF); > } > + free(line); > fclose(fd); > return local; > } I don't see the advantage that the version with malloc brings. It's not necessary to use malloc, so surely it is better to avoid it. There's also the (remote) possibility of malloc failing. James. -- To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html