]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/base/lib_screen.c
ncurses 5.9 - patch 20140308
[ncurses.git] / ncurses / base / lib_screen.c
index 27212b790611f8cba68c17d462d2851675cc75a9..695ed30e7e1000b98011a70b6c0624921ab6ca58 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2011 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -39,7 +39,7 @@
 #define CUR SP_TERMTYPE
 #endif
 
-MODULE_ID("$Id: lib_screen.c,v 1.38 2009/10/24 22:08:55 tom Exp $")
+MODULE_ID("$Id: lib_screen.c,v 1.41 2011/10/22 15:03:11 tom Exp $")
 
 #define MAX_SIZE 0x3fff                /* 16k is big enough for a window or pad */
 
@@ -51,8 +51,11 @@ NCURSES_SP_NAME(getwin) (NCURSES_SP_DCLx FILE *filep)
 
     T((T_CALLED("getwin(%p)"), (void *) filep));
 
+    if (filep == 0) {
+       returnWin(0);
+    }
     clearerr(filep);
-    if (fread(&tmp, 1, sizeof(WINDOW), filep) < sizeof(WINDOW)
+    if (fread(&tmp, (size_t) 1, sizeof(WINDOW), filep) < sizeof(WINDOW)
        || ferror(filep)
        || tmp._maxy == 0
        || tmp._maxy > MAX_SIZE
@@ -110,7 +113,7 @@ NCURSES_SP_NAME(getwin) (NCURSES_SP_DCLx FILE *filep)
 
        for (n = 0; n <= nwin->_maxy; n++) {
            clearerr(filep);
-           if (fread(nwin->_line[n].text, 1, linesize, filep) < linesize
+           if (fread(nwin->_line[n].text, (size_t) 1, linesize, filep) < linesize
                || ferror(filep)) {
                delwin(nwin);
                returnWin(0);
@@ -141,7 +144,7 @@ putwin(WINDOW *win, FILE *filep)
        size_t len = (size_t) (win->_maxx + 1);
 
        clearerr(filep);
-       if (fwrite(win, sizeof(WINDOW), 1, filep) != 1
+       if (fwrite(win, sizeof(WINDOW), (size_t) 1, filep) != 1
            || ferror(filep))
              returnCode(code);
 
@@ -189,18 +192,20 @@ scr_restore(const char *file)
 NCURSES_EXPORT(int)
 scr_dump(const char *file)
 {
+    int result;
     FILE *fp = 0;
 
     T((T_CALLED("scr_dump(%s)"), _nc_visbuf(file)));
 
     if (_nc_access(file, W_OK) < 0
        || (fp = fopen(file, "wb")) == 0) {
-       returnCode(ERR);
+       result = ERR;
     } else {
        (void) putwin(newscr, fp);
        (void) fclose(fp);
-       returnCode(OK);
+       result = OK;
     }
+    returnCode(result);
 }
 
 NCURSES_EXPORT(int)