Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Made declarations of the same functions consistent in Compliant Solution. Removed the POSIX EINVAL.

...

Code Block
bgColor#ccccff
langc
/* sets some internal state in the library */
extern interrno_t setfile(FILE *file);

/* performs some action using the file passed earlier */
extern interrno_t usefile(void);

static FILE *myFile;

errno_t setfile(FILE *file) {
 if (file && !ferror(file) && !feof(file)) {
    myFile = file;
    return 0;
  }

  /* error safety: leave myFile unchaned */
  return EINVAL-1;
}

errno_t usefile(void) {
  if (!myFile) return -1;

    /* perform other checks if needed, return 
     * error condition */

    /* perform some action here */
    return 0;
}

...