Standard I/O v0.1.0

Source
C's <stdio.h>: streams, formatted conversion and the constants that size them.

fclose

pub extern func fclose(stream: *FILE) -> c_int

Closes the given file stream.

See also: https://en.cppreference.com/c/io/fclose

Source

Parameters

NameTypeDescription
stream*FILEthe stream to act on

Returns: zero, or EOF on failure

fgetc

pub extern func fgetc(stream: *FILE) -> c_int

Reads the next character from the given stream.

See also: https://en.cppreference.com/c/io/fgetc

Source

Parameters

NameTypeDescription
stream*FILEthe stream to act on

Returns: the byte as an unsigned char, or EOF at the end or on error

fopen

pub extern func fopen(
    filename: *char8,
    mode: *char8
) -> *FILE

Opens a file indicated by filename with the given mode.

See also: https://en.cppreference.com/c/io/fopen

Source

Parameters

NameTypeDescription
filename*char8the path, as a null-terminated byte string
mode*char8the open mode, such as "rb"

Returns: the stream, or null with the reason in errno

fseek

pub extern func fseek(
    stream: *FILE,
    offset: int64,
    origin: c_int
) -> c_int

Sets the file position indicator for the stream.

See also: https://en.cppreference.com/c/io/fseek

Source

Parameters

NameTypeDescription
stream*FILEthe stream to act on
offsetint64how far to move
originc_intwhere the move is measured from

Returns: zero, or non-zero on failure

ftell

pub extern func ftell(stream: *FILE) -> int64

Returns the current file position of the stream.

See also: https://en.cppreference.com/c/io/ftell

Source

Parameters

NameTypeDescription
stream*FILEthe stream to act on

Returns: the current position, or -1 with the reason in errno

fwrite

pub extern func fwrite(
    buffer: *opaque,
    size: size_t,
    count: size_t,
    stream: *FILE
) -> size_t

Writes count objects of the given size from a buffer to the stream.

See also: https://en.cppreference.com/c/io/fwrite

Source

Parameters

NameTypeDescription
buffer*opaquethe bytes to write
sizesize_thow many bytes one element occupies
countsize_thow many elements to write
stream*FILEthe stream to act on

Returns: how many whole elements were written, which is short only on error

putchar

pub extern func putchar(ch: c_int) -> c_int

Writes a character to stdout.

See also: https://en.cppreference.com/c/io/putchar

Source

Parameters

NameTypeDescription
chc_intthe character, as an int holding an unsigned char value or EOF

Returns: the byte written, or EOF on failure

puts

pub extern func puts(str: *char8) -> c_int

Writes a string followed by a newline to stdout.

See also: https://en.cppreference.com/c/io/puts

Source

Parameters

NameTypeDescription
str*char8a null-terminated byte string

Returns: a non-negative value, or EOF on failure

remove

pub extern func remove(pathname: *char8) -> c_int

Deletes the file identified by the given path.

See also: https://en.cppreference.com/c/io/remove

Source

Parameters

NameTypeDescription
pathname*char8the path, as a null-terminated byte string

Returns: zero, or non-zero on failure

sprintf

pub extern func sprintf(
    buffer: *char8,
    format: *char8,
    ...
) -> c_int

Prints formatted output to a string. Never told the size of the buffer, so a longer result than it holds is an overrun. Rux/Format writes into a destination that knows its own length.

See also: https://en.cppreference.com/c/io/sprintf

Source

Parameters

NameTypeDescription
buffer*char8the bytes
format*char8the format string
...

Returns: how many bytes were written, not counting the terminator, or a negative value on failure

sscanf

pub extern func sscanf(
    buffer: *char8,
    format: *char8,
    ...
) -> c_int

Reads formatted input from a string. A '%s' conversion is never told the size of what it writes into, so a longer field than it holds is an overrun; give every string conversion an explicit width.

See also: https://en.cppreference.com/c/io/sscanf

Source

Parameters

NameTypeDescription
buffer*char8the bytes
format*char8the format string
...

Returns: how many items were assigned, which may be fewer than asked for, or EOF before any were

EOF

pub const EOF: int32 = -1;

EOF: what a character-reading call returns instead of a character when the stream has ended or failed. Negative, and distinct from every unsigned char value, which is why those calls return a c_int rather than a character type. It does not say which of the two happened: feof and ferror do.

Source

SEEK_SET

pub const SEEK_SET: int32 = 0;

SEEK_SET: measure the new stream position from the beginning.

Source

SEEK_CUR

pub const SEEK_CUR: int32 = 1;

SEEK_CUR: measure the new stream position from the current one.

Source

SEEK_END

pub const SEEK_END: int32 = 2;

SEEK_END: measure the new stream position from the end.

Source

_IOFBF

pub const _IOFBF: int32 = 0;

_IOFBF: buffer fully, flushing when the buffer fills.

Source

_IOLBF

// Windows
pub const _IOLBF: int32 = 64;

// Linux · macOS · FreeBSD
pub const _IOLBF: int32 = 1;

_IOLBF: buffer by line.

Source

_IONBF

// Windows
pub const _IONBF: int32 = 4;

// Linux · macOS · FreeBSD
pub const _IONBF: int32 = 2;

_IONBF: do not buffer.

Source

BUFSIZ

// Windows
pub const BUFSIZ: int32 = 512;

// Linux
pub const BUFSIZ: int32 = 8192;

// macOS · FreeBSD
pub const BUFSIZ: int32 = 1024;

BUFSIZ: the buffer size setbuf uses.

Source

FOPEN_MAX

// Windows · macOS · FreeBSD
pub const FOPEN_MAX: int32 = 20;

// Linux
pub const FOPEN_MAX: int32 = 16;

FOPEN_MAX: how many streams the implementation guarantees can be open at once.

Source

FILENAME_MAX

// Windows
pub const FILENAME_MAX: int32 = 260;

// Linux
pub const FILENAME_MAX: int32 = 4096;

// macOS · FreeBSD
pub const FILENAME_MAX: int32 = 1024;

FILENAME_MAX: the length of the longest file name the implementation guarantees it can open.

Source

L_tmpnam

// Windows
pub const L_tmpnam: int32 = 260;

// Linux
pub const L_tmpnam: int32 = 20;

// macOS · FreeBSD
pub const L_tmpnam: int32 = 1024;

L_tmpnam: the buffer size tmpnam needs.

Source

TMP_MAX

// Windows
pub const TMP_MAX: int32 = 32767;

// Linux
pub const TMP_MAX: int32 = 238328;

// macOS · FreeBSD
pub const TMP_MAX: int32 = 308915776;

TMP_MAX: how many distinct names tmpnam guarantees before it repeats.

Source

FILE

pub struct FILE {}

C's FILE: a stream, whose contents belong to the C runtime. Declared with no fields on purpose. Its layout differs by platform and by runtime version, and no binding may read it; a stream is only ever handled through *FILE and the calls that take one. Naming the type rather than using *opaque is what keeps a stream from being passed where some other handle was meant. A *FILE is valid only between the call that produced it and the fclose that ends it. Nothing here tracks that.

Source

fpos_t

pub struct fpos_t {}

C's fpos_t: an opaque record of a position within a stream. Declared with no fields for the same reason FILE is: its contents belong to the C runtime, and it is only ever produced by fgetpos and consumed by fsetpos. It is not a byte offset and must not be arithmetic on.

Source