1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
|
/*
* POSIX library for Lua 5.1, 5.2, 5.3 & 5.4.
* Copyright (C) 2013-2025 Gary V. Vaughan
* Copyright (C) 2010-2013 Reuben Thomas <rrt@sc3d.org>
* Copyright (C) 2008-2010 Natanael Copa <natanael.copa@gmail.com>
* Clean up and bug fixes by Leo Razoumov <slonik.az@gmail.com> 2006-10-11
* Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> 07 Apr 2006 23:17:49
* Based on original by Claudio Terra for Lua 3.x.
* With contributions by Roberto Ierusalimschy.
* With documentation from Steve Donovan 2012
*/
/***
System error codes and messages.
Usually, you'll be able to work with the error messages returned as the
second value from failed calls directly, without having to manually save
and stringify the system messages as you would in C. For completeness,
the functions are still available here.
@module posix.errno
*/
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include "_helpers.c"
#ifndef errno
extern int errno;
#endif
/***
Describe an error code/and or read `errno`
@function errno
@int[opt=current errno] n optional error code
@return description
@return error code
@see strerror(3)
@see errno
@usage
local strerr, nerr = posix.errno ()
*/
static int
Perrno(lua_State *L)
{
int n = optint(L, 1, errno);
checknargs(L, 1);
lua_pushstring(L, strerror(n));
lua_pushinteger(L, n);
return 2;
}
/***
Set errno.
@function set_errno
@int n error code
@see errno(3)
@usage
posix.errno (posix.EBADF)
*/
static int
Pset_errno(lua_State *L)
{
errno = checkint(L, 1);
checknargs(L, 1);
return 0;
}
static const luaL_Reg posix_errno_fns[] =
{
LPOSIX_FUNC( Perrno ),
LPOSIX_FUNC( Pset_errno ),
{NULL, NULL}
};
/***
Constants.
@section constants
*/
/***
Error constants.
Any constants not available in the underlying system will be `nil` valued.
If you find one of the luaposix APIs returns an error code not listed here,
please raise an issue [here](http://github.com/luaposix/luaposixissues), stating
the symbolic name of the constant (from `/usr/include/errno.h` or equivalent).
@table posix.errno
@int E2BIG argument list too long
@int EACCES permission denied
@int EADDRINUSE address already in use
@int EADDRNOTAVAIL can't assign requested address
@int EAFNOSUPPORT address family not supported by protocol family
@int EAGAIN resource temporarily unavailable
@int EALREADY operation already in progress
@int EBADF bad file descriptor
@int EBADMSG bad message
@int EBUSY resource busy
@int ECANCELED operation canceled
@int ECHILD no child processes
@int ECONNABORTED software caused connection abort
@int ECONNREFUSED connection refused
@int ECONNRESET connection reset by peer
@int EDEADLK resource deadlock avoided
@int EDESTADDRREQ destination address required
@int EDOM numerical argument out of domain
@int EEXIST file exists
@int EFAULT bad address
@int EFBIG file too large
@int EHOSTUNREACH no route to host
@int EIDRM identifier removed
@int EILSEQ illegal byte sequence
@int EINPROGRESS operation now in progress
@int EINTR interrupted system call
@int EINVAL invalid argument
@int EIO input/output error
@int EISCONN socket is already connected
@int EISDIR is a directory
@int ELOOP too many levels of symbolic links
@int EMFILE too many open files
@int EMLINK too many links
@int EMSGSIZE message too long
@int ENAMETOOLONG file name too long
@int ENETDOWN network is down
@int ENETRESET network dropped connection on reset
@int ENETUNREACH network is unreachable
@int ENFILE too many open files in system
@int ENOBUFS no buffer space available
@int ENODEV operation not supported by device
@int ENOENT no such file or directory
@int ENOEXEC exec format error
@int ENOLCK no locks available
@int ENOMEM cannot allocate memory
@int ENOMSG no message of desired type
@int ENOPROTOOPT protocol not available
@int ENOSPC no space left on device
@int ENOSYS function not implemented
@int ENOTCONN socket is not connected
@int ENOTDIR not a directory
@int ENOTEMPTY directory not empty
@int ENOTSOCK socket operation on non-socket
@int ENOTSUP operation not supported
@int ENOTTY inappropriate ioctl for device
@int ENXIO device not configured
@int EOPNOTSUPP operation not supported on socket
@int EOVERFLOW value too large to be stored in data type
@int EPERM operation not permitted
@int EPIPE broken pipe
@int EPROTO protocol error
@int EPROTONOSUPPORT protocol not supported
@int EPROTOTYPE protocol wrong type for socket
@int ERANGE result too large
@int EROFS read-only file system
@int ESPIPE illegal seek
@int ESRCH no such process
@int ETIMEDOUT operation timed out
@int ETXTBSY text file busy
@int EWOULDBLOCK operation would block
@int EXDEV cross-device link
@usage
-- Print errno constants supported on this host.
for name, value in pairs (require "posix.errno") do
if type (value) == "number" then
print (name, value)
end
end
*/
LUALIB_API int
luaopen_posix_errno(lua_State *L)
{
luaL_newlib(L, posix_errno_fns);
lua_pushstring(L, LPOSIX_VERSION_STRING("errno"));
lua_setfield(L, -2, "version");
#ifdef E2BIG
LPOSIX_CONST( E2BIG );
#endif
#ifdef EACCES
LPOSIX_CONST( EACCES );
#endif
#ifdef EADDRINUSE
LPOSIX_CONST( EADDRINUSE );
#endif
#ifdef EADDRNOTAVAIL
LPOSIX_CONST( EADDRNOTAVAIL );
#endif
#ifdef EAFNOSUPPORT
LPOSIX_CONST( EAFNOSUPPORT );
#endif
#ifdef EAGAIN
LPOSIX_CONST( EAGAIN );
#endif
#ifdef EALREADY
LPOSIX_CONST( EALREADY );
#endif
#ifdef EBADF
LPOSIX_CONST( EBADF );
#endif
#ifdef EBADMSG
LPOSIX_CONST( EBADMSG );
#endif
#ifdef EBUSY
LPOSIX_CONST( EBUSY );
#endif
#ifdef ECANCELED
LPOSIX_CONST( ECANCELED );
#endif
#ifdef ECHILD
LPOSIX_CONST( ECHILD );
#endif
#ifdef ECONNABORTED
LPOSIX_CONST( ECONNABORTED );
#endif
#ifdef ECONNREFUSED
LPOSIX_CONST( ECONNREFUSED );
#endif
#ifdef ECONNRESET
LPOSIX_CONST( ECONNRESET );
#endif
#ifdef EDEADLK
LPOSIX_CONST( EDEADLK );
#endif
#ifdef EDESTADDRREQ
LPOSIX_CONST( EDESTADDRREQ );
#endif
#ifdef EDOM
LPOSIX_CONST( EDOM );
#endif
#ifdef EEXIST
LPOSIX_CONST( EEXIST );
#endif
#ifdef EFAULT
LPOSIX_CONST( EFAULT );
#endif
#ifdef EFBIG
LPOSIX_CONST( EFBIG );
#endif
#ifdef EHOSTUNREACH
LPOSIX_CONST( EHOSTUNREACH );
#endif
#ifdef EIDRM
LPOSIX_CONST( EIDRM );
#endif
#ifdef EILSEQ
LPOSIX_CONST( EILSEQ );
#endif
#ifdef EINPROGRESS
LPOSIX_CONST( EINPROGRESS );
#endif
#ifdef EINTR
LPOSIX_CONST( EINTR );
#endif
#ifdef EINVAL
LPOSIX_CONST( EINVAL );
#endif
#ifdef EIO
LPOSIX_CONST( EIO );
#endif
#ifdef EISCONN
LPOSIX_CONST( EISCONN );
#endif
#ifdef EISDIR
LPOSIX_CONST( EISDIR );
#endif
#ifdef ELOOP
LPOSIX_CONST( ELOOP );
#endif
#ifdef EMFILE
LPOSIX_CONST( EMFILE );
#endif
#ifdef EMLINK
LPOSIX_CONST( EMLINK );
#endif
#ifdef EMSGSIZE
LPOSIX_CONST( EMSGSIZE );
#endif
#ifdef ENAMETOOLONG
LPOSIX_CONST( ENAMETOOLONG );
#endif
#ifdef ENETDOWN
LPOSIX_CONST( ENETDOWN );
#endif
#ifdef ENETRESET
LPOSIX_CONST( ENETRESET );
#endif
#ifdef ENETUNREACH
LPOSIX_CONST( ENETUNREACH );
#endif
#ifdef ENFILE
LPOSIX_CONST( ENFILE );
#endif
#ifdef ENOBUFS
LPOSIX_CONST( ENOBUFS );
#endif
#ifdef ENODEV
LPOSIX_CONST( ENODEV );
#endif
#ifdef ENOENT
LPOSIX_CONST( ENOENT );
#endif
#ifdef ENOEXEC
LPOSIX_CONST( ENOEXEC );
#endif
#ifdef ENOLCK
LPOSIX_CONST( ENOLCK );
#endif
#ifdef ENOMEM
LPOSIX_CONST( ENOMEM );
#endif
#ifdef ENOMSG
LPOSIX_CONST( ENOMSG );
#endif
#ifdef ENOPROTOOPT
LPOSIX_CONST( ENOPROTOOPT );
#endif
#ifdef ENOSPC
LPOSIX_CONST( ENOSPC );
#endif
#ifdef ENOSYS
LPOSIX_CONST( ENOSYS );
#endif
#ifdef ENOTCONN
LPOSIX_CONST( ENOTCONN );
#endif
#ifdef ENOTDIR
LPOSIX_CONST( ENOTDIR );
#endif
#ifdef ENOTEMPTY
LPOSIX_CONST( ENOTEMPTY );
#endif
#ifdef ENOTSOCK
LPOSIX_CONST( ENOTSOCK );
#endif
#ifdef ENOTSUP
LPOSIX_CONST( ENOTSUP );
#endif
#ifdef ENOTTY
LPOSIX_CONST( ENOTTY );
#endif
#ifdef ENXIO
LPOSIX_CONST( ENXIO );
#endif
#ifdef EOPNOTSUPP
LPOSIX_CONST( EOPNOTSUPP );
#endif
#ifdef EOVERFLOW
LPOSIX_CONST( EOVERFLOW );
#endif
#ifdef EPERM
LPOSIX_CONST( EPERM );
#endif
#ifdef EPIPE
LPOSIX_CONST( EPIPE );
#endif
#ifdef EPROTO
LPOSIX_CONST( EPROTO );
#endif
#ifdef EPROTONOSUPPORT
LPOSIX_CONST( EPROTONOSUPPORT );
#endif
#ifdef EPROTOTYPE
LPOSIX_CONST( EPROTOTYPE );
#endif
#ifdef ERANGE
LPOSIX_CONST( ERANGE );
#endif
#ifdef EROFS
LPOSIX_CONST( EROFS );
#endif
#ifdef ESPIPE
LPOSIX_CONST( ESPIPE );
#endif
#ifdef ESRCH
LPOSIX_CONST( ESRCH );
#endif
#ifdef ETIMEDOUT
LPOSIX_CONST( ETIMEDOUT );
#endif
#ifdef ETXTBSY
LPOSIX_CONST( ETXTBSY );
#endif
#ifdef EWOULDBLOCK
LPOSIX_CONST( EWOULDBLOCK );
#endif
#ifdef EXDEV
LPOSIX_CONST( EXDEV );
#endif
return 1;
}
|