|
40 | 40 | posix_close/1, |
41 | 41 | posix_read/2, |
42 | 42 | posix_write/2, |
| 43 | + posix_seek/3, |
| 44 | + posix_pread/3, |
| 45 | + posix_pwrite/3, |
| 46 | + posix_fsync/1, |
| 47 | + posix_ftruncate/2, |
| 48 | + posix_mkfifo/2, |
| 49 | + posix_mkdir/2, |
| 50 | + posix_rmdir/1, |
| 51 | + posix_rename/2, |
| 52 | + posix_stat/1, |
| 53 | + posix_fstat/1, |
43 | 54 | posix_clock_settime/2, |
44 | 55 | posix_opendir/1, |
45 | 56 | posix_closedir/1, |
|
51 | 62 | -export_type([ |
52 | 63 | posix_fd/0, |
53 | 64 | posix_open_flag/0, |
| 65 | + posix_whence/0, |
| 66 | + posix_stat_info/0, |
54 | 67 | posix_dir/0 |
55 | 68 | ]). |
56 | 69 |
|
|
89 | 102 | -type posix_error() :: |
90 | 103 | atom() |
91 | 104 | | integer(). |
| 105 | +-type posix_whence() :: |
| 106 | + seek_set |
| 107 | + | seek_cur |
| 108 | + | seek_end. |
| 109 | +-type posix_stat_info() :: #{ |
| 110 | + st_dev := integer(), |
| 111 | + st_ino := integer(), |
| 112 | + st_mode := integer(), |
| 113 | + st_nlink := integer(), |
| 114 | + st_uid := integer(), |
| 115 | + st_gid := integer(), |
| 116 | + st_size := integer(), |
| 117 | + st_atime_s := integer(), |
| 118 | + st_mtime_s := integer(), |
| 119 | + st_ctime_s := integer() |
| 120 | +}. |
92 | 121 |
|
93 | 122 | -opaque posix_dir() :: binary(). |
94 | 123 |
|
@@ -282,6 +311,134 @@ posix_read(_File, _Count) -> |
282 | 311 | posix_write(_File, _Data) -> |
283 | 312 | erlang:nif_error(undefined). |
284 | 313 |
|
| 314 | +%%----------------------------------------------------------------------------- |
| 315 | +%% @param File Descriptor to an open file |
| 316 | +%% @param Offset Offset in bytes |
| 317 | +%% @param Whence Reference point for the offset |
| 318 | +%% @returns a tuple with the resulting absolute offset or an error tuple |
| 319 | +%% @doc Reposition the file cursor using `lseek(2)'. |
| 320 | +%% @end |
| 321 | +%%----------------------------------------------------------------------------- |
| 322 | +-spec posix_seek(File :: posix_fd(), Offset :: integer(), Whence :: posix_whence()) -> |
| 323 | + {ok, integer()} | {error, posix_error()}. |
| 324 | +posix_seek(_File, _Offset, _Whence) -> |
| 325 | + erlang:nif_error(undefined). |
| 326 | + |
| 327 | +%%----------------------------------------------------------------------------- |
| 328 | +%% @param File Descriptor to an open file |
| 329 | +%% @param Count Maximum number of bytes to read |
| 330 | +%% @param Offset Offset in bytes from the start of the file |
| 331 | +%% @returns a tuple with read bytes, `eof' or an error tuple |
| 332 | +%% @doc Read at most `Count' bytes from a file at a given offset using |
| 333 | +%% `pread(2)'. The file cursor is not modified. |
| 334 | +%% @end |
| 335 | +%%----------------------------------------------------------------------------- |
| 336 | +-spec posix_pread(File :: posix_fd(), Count :: non_neg_integer(), Offset :: non_neg_integer()) -> |
| 337 | + {ok, binary()} | eof | {error, posix_error()}. |
| 338 | +posix_pread(_File, _Count, _Offset) -> |
| 339 | + erlang:nif_error(undefined). |
| 340 | + |
| 341 | +%%----------------------------------------------------------------------------- |
| 342 | +%% @param File Descriptor to an open file |
| 343 | +%% @param Data Data to write |
| 344 | +%% @param Offset Offset in bytes from the start of the file |
| 345 | +%% @returns a tuple with the number of written bytes or an error tuple |
| 346 | +%% @doc Write data to a file at a given offset using `pwrite(2)'. |
| 347 | +%% The file cursor is not modified. |
| 348 | +%% @end |
| 349 | +%%----------------------------------------------------------------------------- |
| 350 | +-spec posix_pwrite(File :: posix_fd(), Data :: binary(), Offset :: non_neg_integer()) -> |
| 351 | + {ok, non_neg_integer()} | {error, posix_error()}. |
| 352 | +posix_pwrite(_File, _Data, _Offset) -> |
| 353 | + erlang:nif_error(undefined). |
| 354 | + |
| 355 | +%%----------------------------------------------------------------------------- |
| 356 | +%% @param File Descriptor to an open file |
| 357 | +%% @returns `ok' or an error tuple |
| 358 | +%% @doc Flush file data to storage using `fsync(2)'. |
| 359 | +%% @end |
| 360 | +%%----------------------------------------------------------------------------- |
| 361 | +-spec posix_fsync(File :: posix_fd()) -> ok | {error, posix_error()}. |
| 362 | +posix_fsync(_File) -> |
| 363 | + erlang:nif_error(undefined). |
| 364 | + |
| 365 | +%%----------------------------------------------------------------------------- |
| 366 | +%% @param File Descriptor to an open file |
| 367 | +%% @param Length Desired file length in bytes |
| 368 | +%% @returns `ok' or an error tuple |
| 369 | +%% @doc Truncate a file to a specified length using `ftruncate(2)'. |
| 370 | +%% If the file is larger than `Length', the extra data is lost. If the file |
| 371 | +%% is shorter, it is extended with null bytes. |
| 372 | +%% @end |
| 373 | +%%----------------------------------------------------------------------------- |
| 374 | +-spec posix_ftruncate(File :: posix_fd(), Length :: non_neg_integer()) -> |
| 375 | + ok | {error, posix_error()}. |
| 376 | +posix_ftruncate(_File, _Length) -> |
| 377 | + erlang:nif_error(undefined). |
| 378 | + |
| 379 | +%%----------------------------------------------------------------------------- |
| 380 | +%% @param Path Path to the new FIFO special file |
| 381 | +%% @param Mode Permission bits for the new FIFO |
| 382 | +%% @returns `ok' or an error tuple |
| 383 | +%% @doc Create a FIFO special file (named pipe) using `mkfifo(2)'. |
| 384 | +%% @end |
| 385 | +%%----------------------------------------------------------------------------- |
| 386 | +-spec posix_mkfifo(Path :: iodata(), Mode :: non_neg_integer()) -> |
| 387 | + ok | {error, posix_error()}. |
| 388 | +posix_mkfifo(_Path, _Mode) -> |
| 389 | + erlang:nif_error(undefined). |
| 390 | + |
| 391 | +%%----------------------------------------------------------------------------- |
| 392 | +%% @param Path Path to the directory to create |
| 393 | +%% @param Mode Permission bits for the new directory |
| 394 | +%% @returns `ok' or an error tuple |
| 395 | +%% @doc Create a directory using `mkdir(2)'. |
| 396 | +%% @end |
| 397 | +%%----------------------------------------------------------------------------- |
| 398 | +-spec posix_mkdir(Path :: iodata(), Mode :: non_neg_integer()) -> |
| 399 | + ok | {error, posix_error()}. |
| 400 | +posix_mkdir(_Path, _Mode) -> |
| 401 | + erlang:nif_error(undefined). |
| 402 | + |
| 403 | +%%----------------------------------------------------------------------------- |
| 404 | +%% @param Path Path to the directory to remove |
| 405 | +%% @returns ok or an error tuple |
| 406 | +%% @doc Remove an empty directory using `rmdir(2)'. |
| 407 | +%% @end |
| 408 | +%%----------------------------------------------------------------------------- |
| 409 | +-spec posix_rmdir(Path :: iodata()) -> |
| 410 | + ok | {error, posix_error()}. |
| 411 | +posix_rmdir(_Path) -> |
| 412 | + erlang:nif_error(undefined). |
| 413 | + |
| 414 | +%%----------------------------------------------------------------------------- |
| 415 | +-spec posix_rename(OldPath :: iodata(), NewPath :: iodata()) -> |
| 416 | + ok | {error, posix_error()}. |
| 417 | +posix_rename(_OldPath, _NewPath) -> |
| 418 | + erlang:nif_error(undefined). |
| 419 | + |
| 420 | +%%----------------------------------------------------------------------------- |
| 421 | +%% @param Path Path to the file |
| 422 | +%% @returns a tuple with a map of file information or an error tuple |
| 423 | +%% @doc Get file status using `stat(2)'. |
| 424 | +%% @end |
| 425 | +%%----------------------------------------------------------------------------- |
| 426 | +-spec posix_stat(Path :: iodata()) -> |
| 427 | + {ok, posix_stat_info()} | {error, posix_error()}. |
| 428 | +posix_stat(_Path) -> |
| 429 | + erlang:nif_error(undefined). |
| 430 | + |
| 431 | +%%----------------------------------------------------------------------------- |
| 432 | +%% @param File Descriptor to an open file |
| 433 | +%% @returns a tuple with a map of file information or an error tuple |
| 434 | +%% @doc Get file status from a file descriptor using `fstat(2)'. |
| 435 | +%% @end |
| 436 | +%%----------------------------------------------------------------------------- |
| 437 | +-spec posix_fstat(File :: posix_fd()) -> |
| 438 | + {ok, posix_stat_info()} | {error, posix_error()}. |
| 439 | +posix_fstat(_File) -> |
| 440 | + erlang:nif_error(undefined). |
| 441 | + |
285 | 442 | %% |
286 | 443 | %% @param ClockId The clock id |
287 | 444 | %% @param ValueSinceUnixEpoch The value, in specified seconds and nanoseconds, |
|
0 commit comments