Software /
code /
prosody
Comparison
util-src/pposix.c @ 6154:dfe88a0e18fd
util.pposix: Fix error reporting from posix_fallocate, it doesn't use errno (thanks pro)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 25 Apr 2014 00:36:01 +0200 |
parent | 5927:49e3c49eb0d8 |
child | 6155:dc3497041aca |
comparison
equal
deleted
inserted
replaced
6148:7dcd6f124c93 | 6154:dfe88a0e18fd |
---|---|
662 * */ | 662 * */ |
663 | 663 |
664 #if _XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L || defined(_GNU_SOURCE) | 664 #if _XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L || defined(_GNU_SOURCE) |
665 int lc_fallocate(lua_State* L) | 665 int lc_fallocate(lua_State* L) |
666 { | 666 { |
667 int ret; | |
667 off_t offset, len; | 668 off_t offset, len; |
668 FILE *f = *(FILE**) luaL_checkudata(L, 1, LUA_FILEHANDLE); | 669 FILE *f = *(FILE**) luaL_checkudata(L, 1, LUA_FILEHANDLE); |
669 if (f == NULL) | 670 if (f == NULL) |
670 luaL_error(L, "attempt to use a closed file"); | 671 luaL_error(L, "attempt to use a closed file"); |
671 | 672 |
689 #warning Only using posix_fallocate() fallback. | 690 #warning Only using posix_fallocate() fallback. |
690 #warning Linux fallocate() is strongly recommended if available: recompile with -D_GNU_SOURCE | 691 #warning Linux fallocate() is strongly recommended if available: recompile with -D_GNU_SOURCE |
691 #warning Note that posix_fallocate() will still be used on filesystems that dont support fallocate() | 692 #warning Note that posix_fallocate() will still be used on filesystems that dont support fallocate() |
692 #endif | 693 #endif |
693 | 694 |
694 if(posix_fallocate(fileno(f), offset, len) == 0) | 695 ret = posix_fallocate(fileno(f), offset, len); |
696 if(ret == 0) | |
695 { | 697 { |
696 lua_pushboolean(L, 1); | 698 lua_pushboolean(L, 1); |
697 return 1; | 699 return 1; |
698 } | 700 } |
699 else | 701 else |
700 { | 702 { |
701 lua_pushnil(L); | 703 lua_pushnil(L); |
702 lua_pushstring(L, strerror(errno)); | 704 lua_pushstring(L, strerror(ret)); |
703 /* posix_fallocate() can leave a bunch of NULs at the end, so we cut that | 705 /* posix_fallocate() can leave a bunch of NULs at the end, so we cut that |
704 * this assumes that offset == length of the file */ | 706 * this assumes that offset == length of the file */ |
705 ftruncate(fileno(f), offset); | 707 ftruncate(fileno(f), offset); |
706 return 2; | 708 return 2; |
707 } | 709 } |