-/* $Id: plugin_file.c,v 1.1 2006/02/19 15:42:19 reinelt Exp $
+/* $Id: plugin_file.c,v 1.2 2006/07/19 01:57:01 cmay Exp $
  *
  * plugin to perform simple file operations
  *
  *
  *
  * $Log: plugin_file.c,v $
+ * Revision 1.2  2006/07/19 01:57:01  cmay
+ * fixed double read of last line in file
+ *
  * Revision 1.1  2006/02/19 15:42:19  reinelt
  * file plugin from Chris Maj
  *
        error("readline couldn't open file '%s'", R2S(arg1));
     } else {
        i = 0;
-       while (!feof(fp) && i < reqline) {
+       while (!feof(fp) && i++ < reqline) {
            fgets(val2, sizeof(val2), fp);
            size = strcspn(val2, "\n");
            strncpy(value, val2, size);
                fgets(val2, sizeof(val2), fp);
                pos = strchr(val2, '\n');
            }
-           i++;
        }
        fclose(fp);
-       if (i < reqline) {
-           error("readline requested line %d but file only had %d lines", reqline, i);
+       if (i <= reqline) {
+           error("readline requested line %d but file only had %d lines", reqline, i - 1);
            value[0] = '\0';
        }
     }