Exemplo n.º 1
0
static int lfs_g_setmode(lua_State *L, FILE *f, int arg) {
	static const int mode[] = { _O_BINARY, _O_TEXT };
	static const char *const modenames[] = { "binary", "text", NULL };
	int op = luaL_checkoption(L, arg, NULL, modenames);
	int res = lfs_setmode(L, f, mode[op]);
	if (res != -1) {
		int i;
		lua_pushboolean(L, 1);
		for (i = 0; modenames[i] != NULL; i++) {
			if (mode[i] == res) {
				lua_pushstring(L, modenames[i]);
				goto exit;
			}
		}
		lua_pushnil(L);
	exit:
		return 2;
	}
	else {
		int en = errno;
		lua_pushnil(L);
		lua_pushfstring(L, "%s", strerror(en));
		lua_pushinteger(L, en);
		return 3;
	}
}
Exemplo n.º 2
0
static int lfs_g_setmode (lua_State *L, FILE *f, int arg) {
  static const int mode[] = {_O_BINARY, _O_TEXT};
  static const char *const modenames[] = {"binary", "text", NULL};
  int op = luaL_checkoption(L, arg, NULL, modenames);
  int res = lfs_setmode(f, mode[op]);
  if (res != -1) {
    int i;
    lua_pushboolean(L, 1);
    for (i = 0; modenames[i] != NULL; i++) {
      if (mode[i] == res) {
        lua_pushstring(L, modenames[i]);
        return 2;
      }
    }
    lua_pushnil(L);
    return 2;
  } else {
    return pusherror(L, NULL);
  }
}