aboutsummaryrefslogtreecommitdiff
path: root/liolib.c
diff options
context:
space:
mode:
Diffstat (limited to 'liolib.c')
-rw-r--r--liolib.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/liolib.c b/liolib.c
index 79516724..b08397da 100644
--- a/liolib.c
+++ b/liolib.c
@@ -186,7 +186,7 @@ static int f_tostring (lua_State *L) {
186 186
187static FILE *tofile (lua_State *L) { 187static FILE *tofile (lua_State *L) {
188 LStream *p = tolstream(L); 188 LStream *p = tolstream(L);
189 if (isclosed(p)) 189 if (l_unlikely(isclosed(p)))
190 luaL_error(L, "attempt to use a closed file"); 190 luaL_error(L, "attempt to use a closed file");
191 lua_assert(p->f); 191 lua_assert(p->f);
192 return p->f; 192 return p->f;
@@ -261,7 +261,7 @@ static LStream *newfile (lua_State *L) {
261static void opencheck (lua_State *L, const char *fname, const char *mode) { 261static void opencheck (lua_State *L, const char *fname, const char *mode) {
262 LStream *p = newfile(L); 262 LStream *p = newfile(L);
263 p->f = fopen(fname, mode); 263 p->f = fopen(fname, mode);
264 if (p->f == NULL) 264 if (l_unlikely(p->f == NULL))
265 luaL_error(L, "cannot open file '%s' (%s)", fname, strerror(errno)); 265 luaL_error(L, "cannot open file '%s' (%s)", fname, strerror(errno));
266} 266}
267 267
@@ -309,7 +309,7 @@ static FILE *getiofile (lua_State *L, const char *findex) {
309 LStream *p; 309 LStream *p;
310 lua_getfield(L, LUA_REGISTRYINDEX, findex); 310 lua_getfield(L, LUA_REGISTRYINDEX, findex);
311 p = (LStream *)lua_touserdata(L, -1); 311 p = (LStream *)lua_touserdata(L, -1);
312 if (isclosed(p)) 312 if (l_unlikely(isclosed(p)))
313 luaL_error(L, "default %s file is closed", findex + IOPREF_LEN); 313 luaL_error(L, "default %s file is closed", findex + IOPREF_LEN);
314 return p->f; 314 return p->f;
315} 315}
@@ -436,7 +436,7 @@ typedef struct {
436** Add current char to buffer (if not out of space) and read next one 436** Add current char to buffer (if not out of space) and read next one
437*/ 437*/
438static int nextc (RN *rn) { 438static int nextc (RN *rn) {
439 if (rn->n >= L_MAXLENNUM) { /* buffer overflow? */ 439 if (l_unlikely(rn->n >= L_MAXLENNUM)) { /* buffer overflow? */
440 rn->buff[0] = '\0'; /* invalidate result */ 440 rn->buff[0] = '\0'; /* invalidate result */
441 return 0; /* fail */ 441 return 0; /* fail */
442 } 442 }
@@ -499,8 +499,8 @@ static int read_number (lua_State *L, FILE *f) {
499 ungetc(rn.c, rn.f); /* unread look-ahead char */ 499 ungetc(rn.c, rn.f); /* unread look-ahead char */
500 l_unlockfile(rn.f); 500 l_unlockfile(rn.f);
501 rn.buff[rn.n] = '\0'; /* finish string */ 501 rn.buff[rn.n] = '\0'; /* finish string */
502 if (lua_stringtonumber(L, rn.buff)) /* is this a valid number? */ 502 if (l_likely(lua_stringtonumber(L, rn.buff)))
503 return 1; /* ok */ 503 return 1; /* ok, it is a valid number */
504 else { /* invalid format */ 504 else { /* invalid format */
505 lua_pushnil(L); /* "result" to be removed */ 505 lua_pushnil(L); /* "result" to be removed */
506 return 0; /* read fails */ 506 return 0; /* read fails */
@@ -676,7 +676,8 @@ static int g_write (lua_State *L, FILE *f, int arg) {
676 status = status && (fwrite(s, sizeof(char), l, f) == l); 676 status = status && (fwrite(s, sizeof(char), l, f) == l);
677 } 677 }
678 } 678 }
679 if (status) return 1; /* file handle already on stack top */ 679 if (l_likely(status))
680 return 1; /* file handle already on stack top */
680 else return luaL_fileresult(L, status, NULL); 681 else return luaL_fileresult(L, status, NULL);
681} 682}
682 683
@@ -703,7 +704,7 @@ static int f_seek (lua_State *L) {
703 luaL_argcheck(L, (lua_Integer)offset == p3, 3, 704 luaL_argcheck(L, (lua_Integer)offset == p3, 3,
704 "not an integer in proper range"); 705 "not an integer in proper range");
705 op = l_fseek(f, offset, mode[op]); 706 op = l_fseek(f, offset, mode[op]);
706 if (op) 707 if (l_unlikely(op))
707 return luaL_fileresult(L, 0, NULL); /* error */ 708 return luaL_fileresult(L, 0, NULL); /* error */
708 else { 709 else {
709 lua_pushinteger(L, (lua_Integer)l_ftell(f)); 710 lua_pushinteger(L, (lua_Integer)l_ftell(f));