noarch

package
v0.14.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2017 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package noarch contains low-level functions that apply to multiple platforms.

Index

Constants

This section is empty.

Variables

View Source
var (
	Stdin  = NewFile(os.Stdin)
	Stdout = NewFile(os.Stdout)
	Stderr = NewFile(os.Stderr)
)

Programs generated by c2go will reference noarch.Stdin instead of os.Stdin directly so that under test these can be replaced. This is required because "go test" does not redirect the stdin to the executable it is testing.

Functions

func Atoi added in v0.9.0

func Atoi(a []byte) int

Atoi parses the C-string str interpreting its content as an integral number, which is returned as a value of type int.

The function first discards as many whitespace characters (as in isspace) as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many base-10 digits as possible, and interprets them as a numerical value.

The string can contain additional characters after those that form the integral number, which are ignored and have no effect on the behavior of this function.

If the first sequence of non-whitespace characters in str is not a valid integral number, or if no such sequence exists because either str is empty or it contains only whitespace characters, no conversion is performed and zero is returned.

func BoolToInt

func BoolToInt(x bool) int

BoolToInt converts boolean value to an int, which is a common operation in C. 0 and 1 represent false and true respectively.

func CPointerToGoPointer added in v0.14.0

func CPointerToGoPointer(a interface{}) interface{}

CPointerToGoPointer converts a C-style pointer into a Go-style pointer.

C pointers are represented as slices that have one element pointing to where the original C pointer would be referencing. This isn't useful if the pointed value needs to be passed to another Go function in these libraries.

See also GoPointerToCPointer.

func CStringIsNull added in v0.13.0

func CStringIsNull(s []byte) bool

CStringIsNull will test if a C string is NULL. This is equivalent to:

s == NULL

func CStringToString added in v0.14.0

func CStringToString(s []byte) string

CStringToString returns a string that contains all the bytes in the provided C string up until the first NULL character.

func Fclose added in v0.9.0

func Fclose(f *File) int

Fclose handles fclose().

Closes the file associated with the stream and disassociates it.

All internal buffers associated with the stream are disassociated from it and flushed: the content of any unwritten output buffer is written and the content of any unread input buffer is discarded.

Even if the call fails, the stream passed as parameter will no longer be associated with the file nor its buffers.

func Feof added in v0.11.0

func Feof(stream *File) int

Feof handles feof().

Checks whether the end-of-File indicator associated with stream is set, returning a value different from zero if it is.

This indicator is generally set by a previous operation on the stream that attempted to read at or past the end-of-file.

Notice that stream's internal position indicator may point to the end-of-file for the next operation, but still, the end-of-file indicator may not be set until an operation attempts to read at that point.

This indicator is cleared by a call to clearerr, rewind, fseek, fsetpos or freopen. Although if the position indicator is not repositioned by such a call, the next i/o operation is likely to set the indicator again.

func Fflush added in v0.11.0

func Fflush(stream *File) int

Fflush handles fflush().

If the given stream was open for writing (or if it was open for updating and the last i/o operation was an output operation) any unwritten data in its output buffer is written to the file.

If stream is a null pointer, all such streams should be flushed, but this is currently not supported.

The stream remains open after this call.

When a file is closed, either because of a call to fclose or because the program terminates, all the buffers associated with it are automatically flushed.

func Fgetc added in v0.11.0

func Fgetc(stream *File) int

Fgetc handles fgetc().

Returns the character currently pointed by the internal file position indicator of the specified stream. The internal file position indicator is then advanced to the next character.

If the stream is at the end-of-file when called, the function returns EOF and sets the end-of-file indicator for the stream (feof).

If a read error occurs, the function returns EOF and sets the error indicator for the stream (ferror).

fgetc and getc are equivalent, except that getc may be implemented as a macro in some libraries.

func Fgetpos added in v0.11.0

func Fgetpos(f *File, pos []int) int

Fgetpos handles fgetpos().

Retrieves the current position in the stream.

The function fills the fpos_t object pointed by pos with the information needed from the stream's position indicator to restore the stream to its current position (and multibyte state, if wide-oriented) with a call to fsetpos.

The ftell function can be used to retrieve the current position in the stream as an integer value.

func Fgets added in v0.11.0

func Fgets(str []byte, num int, stream *File) []byte

Fgets handles fgets().

Reads characters from stream and stores them as a C string into str until (num-1) characters have been read or either a newline or the end-of-file is reached, whichever happens first.

A newline character makes fgets stop reading, but it is considered a valid character by the function and included in the string copied to str.

A terminating null character is automatically appended after the characters copied to str.

Notice that fgets is quite different from gets: not only fgets accepts a stream argument, but also allows to specify the maximum size of str and includes in the string any ending newline character.

func Fprintf added in v0.11.0

func Fprintf(f *File, format []byte, args ...interface{}) int

Fprintf handles fprintf().

Writes the C string pointed by format to the stream. If format includes format specifiers (subsequences beginning with %), the additional arguments following format are formatted and inserted in the resulting string replacing their respective specifiers.

After the format parameter, the function expects at least as many additional arguments as specified by format.

func Fputc added in v0.11.0

func Fputc(c int, f *File) int

Fputc handles fputc().

Writes a character to the stream and advances the position indicator.

The character is written at the position indicated by the internal position indicator of the stream, which is then automatically advanced by one.

func Fputs added in v0.11.0

func Fputs(str []byte, stream *File) int

Fputs handles fputs().

Writes the C string pointed by str to the stream.

The function begins copying from the address specified (str) until it reaches the terminating null character ('\0'). This terminating null-character is not copied to the stream.

Notice that fputs not only differs from puts in that the destination stream can be specified, but also fputs does not write additional characters, while puts appends a newline character at the end automatically.

func Fread added in v0.11.0

func Fread(ptr *[]byte, size1, size2 int, f *File) int

Fread handles fread().

Reads an array of count elements, each one with a size of size bytes, from the stream and stores them in the block of memory specified by ptr.

The position indicator of the stream is advanced by the total amount of bytes read.

The total amount of bytes read if successful is (size*count).

func Free added in v0.12.0

func Free(anything interface{})

Free doesn't do anything since memory is managed by the Go garbage collector. However, I will leave it here as a placeholder for now.

func Fscanf added in v0.11.0

func Fscanf(f *File, format []byte, args ...interface{}) int

Fscanf handles fscanf().

Reads data from the stream and stores them according to the parameter format into the locations pointed by the additional arguments.

The additional arguments should point to already allocated objects of the type specified by their corresponding format specifier within the format string.

func Fseek added in v0.11.0

func Fseek(f *File, offset int32, origin int) int

Fseek handles fseek().

Sets the position indicator associated with the stream to a new position.

For streams open in binary mode, the new position is defined by adding offset to a reference position specified by origin.

For streams open in text mode, offset shall either be zero or a value returned by a previous call to ftell, and origin shall necessarily be SEEK_SET.

If the function is called with other values for these arguments, support depends on the particular system and library implementation (non-portable).

The end-of-file internal indicator of the stream is cleared after a successful call to this function, and all effects from previous calls to ungetc on this stream are dropped.

On streams open for update (read+write), a call to fseek allows to switch between reading and writing.

func Fsetpos added in v0.11.0

func Fsetpos(stream *File, pos []int) int

Fsetpos handles fsetpos().

Restores the current position in the stream to pos.

The internal file position indicator associated with stream is set to the position represented by pos, which is a pointer to an fpos_t object whose value shall have been previously obtained by a call to fgetpos.

The end-of-file internal indicator of the stream is cleared after a successful call to this function, and all effects from previous calls to ungetc on this stream are dropped.

On streams open for update (read+write), a call to fsetpos allows to switch between reading and writing.

A similar function, fseek, can be used to set arbitrary positions on streams open in binary mode.

func Ftell added in v0.11.0

func Ftell(f *File) int32

Ftell handles ftell().

Returns the current value of the position indicator of the stream.

For binary streams, this is the number of bytes from the beginning of the file.

For text streams, the numerical value may not be meaningful but can still be used to restore the position to the same position later using fseek (if there are characters put back using ungetc still pending of being read, the behavior is undefined).

func Fwrite added in v0.11.0

func Fwrite(str []byte, size1, size2 int, stream *File) int

Fwrite handles fwrite().

Writes an array of count elements, each one with a size of size bytes, from the block of memory pointed by ptr to the current position in the stream.

The position indicator of the stream is advanced by the total number of bytes written.

Internally, the function interprets the block pointed by ptr as if it was an array of (size*count) elements of type unsigned char, and writes them sequentially to stream as if fputc was called for each byte.

func Getchar added in v0.11.0

func Getchar() int

Getchar handles getchar().

Returns the next character from the standard input (stdin).

It is equivalent to calling getc with stdin as argument.

func GoPointerToCPointer added in v0.14.0

func GoPointerToCPointer(destination interface{}, value interface{})

GoPointerToCPointer does the opposite of CPointerToGoPointer.

A Go pointer (simply a pointer) is converted back into the original slice structure (of the original slice reference) so that the calling functions will be able to see the new data of that pointer.

func IsNaN added in v0.13.0

func IsNaN(x float64) int

func NotInt

func NotInt(x int) int

NotInt performs a logical not (!) on an integer and returns an integer.

func NotUint16 added in v0.9.0

func NotUint16(x uint16) uint16

NotUint16 works the same as NotInt, but on a uint16.

func Printf added in v0.12.0

func Printf(format []byte, args ...interface{}) int

Printf handles printf().

Writes the C string pointed by format to the standard output (stdout). If format includes format specifiers (subsequences beginning with %), the additional arguments following format are formatted and inserted in the resulting string replacing their respective specifiers.

func Putchar added in v0.13.7

func Putchar(character int)

Putchar handles putchar().

Writes a character to the standard output (stdout).

It is equivalent to calling putc with stdout as second argument.

func Puts added in v0.12.0

func Puts(str []byte) int

Puts handles puts().

Writes the C string pointed by str to the standard output (stdout) and appends a newline character ('\n').

The function begins copying from the address specified (str) until it reaches the terminating null character ('\0'). This terminating null-character is not copied to the stream.

Notice that puts not only differs from fputs in that it uses stdout as destination, but it also appends a newline character at the end automatically (which fputs does not).

func Remove added in v0.11.0

func Remove(filePath []byte) int

Remove handles remove().

Deletes the file whose name is specified in filePath.

This is an operation performed directly on a file identified by its filePath; No streams are involved in the operation.

Proper file access shall be available.

func Rename added in v0.11.0

func Rename(oldName, newName []byte) int

Rename handles rename().

Changes the name of the file or directory specified by oldName to newName.

This is an operation performed directly on a file; No streams are involved in the operation.

If oldName and newName specify different paths and this is supported by the system, the file is moved to the new location.

If newName names an existing file, the function may either fail or override the existing file, depending on the specific system and library implementation.

Proper file access shall be available.

func Rewind added in v0.11.0

func Rewind(stream *File)

Rewind handles rewind().

Sets the position indicator associated with stream to the beginning of the file.

The end-of-file and error internal indicators associated to the stream are cleared after a successful call to this function, and all effects from previous calls to ungetc on this stream are dropped.

On streams open for update (read+write), a call to rewind allows to switch between reading and writing.

func Scanf added in v0.12.0

func Scanf(format []byte, args ...interface{}) int

Scanf handles scanf().

Reads data from stdin and stores them according to the parameter format into the locations pointed by the additional arguments.

The additional arguments should point to already allocated objects of the type specified by their corresponding format specifier within the format string.

func Signbitd added in v0.13.0

func Signbitd(x float64) int

func Signbitf added in v0.13.0

func Signbitf(x float32) int

func Signbitl added in v0.13.0

func Signbitl(x float64) int

func Strlen added in v0.11.0

func Strlen(a []byte) int

Strlen returns the length of a string.

The length of a C string is determined by the terminating null-character: A C string is as long as the number of characters between the beginning of the string and the terminating null character (without including the terminating null character itself).

func Strtol added in v0.9.0

func Strtol(a, b []byte, c int) int32

Strtol parses the C-string str interpreting its content as an integral number of the specified base, which is returned as a long int value. If endptr is not a null pointer, the function also sets the value of endptr to point to the first character after the number.

The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes as many characters as possible that are valid following a syntax that depends on the base parameter, and interprets them as a numerical value. Finally, a pointer to the first character following the integer representation in str is stored in the object pointed by endptr.

If the value of base is zero, the syntax expected is similar to that of integer constants, which is formed by a succession of:

  • An optional sign character (+ or -)
  • An optional prefix indicating octal or hexadecimal base ("0" or "0x"/"0X" respectively)

A sequence of decimal digits (if no base prefix was specified) or either octal or hexadecimal digits if a specific prefix is present

If the base value is between 2 and 36, the format expected for the integral number is a succession of any of the valid digits and/or letters needed to represent integers of the specified radix (starting from '0' and up to 'z'/'Z' for radix 36). The sequence may optionally be preceded by a sign (either + or -) and, if base is 16, an optional "0x" or "0X" prefix.

If the first sequence of non-whitespace characters in str is not a valid integral number as defined above, or if no such sequence exists because either str is empty or it contains only whitespace characters, no conversion is performed.

For locales other than the "C" locale, additional subject sequence forms may be accepted.

func Ternary

func Ternary(a bool, b, c func() interface{}) interface{}

Ternary simulates the ternary (also known as the conditional operator). Go does not have the equivilent of using if statements as expressions or inline if statements. This function takes the true and false parts as closures to be sure that only the true or false condition is evaulated - to prevent side effects.

func Tmpnam added in v0.11.0

func Tmpnam(str []byte) []byte

Tmpnam handles tmpnam().

Returns a string containing a file name different from the name of any existing file, and thus suitable to safely create a temporary file without risking to overwrite an existing file.

If str is a null pointer, the resulting string is stored in an internal static array that can be accessed by the return value. The content of this string is preserved at least until a subsequent call to this same function, which may overwrite it.

If str is not a null pointer, it shall point to an array of at least L_tmpnam characters that will be filled with the proposed temporary file name.

The file name returned by this function can be used to create a regular file using fopen to be used as a temporary file. The file created this way, unlike those created with tmpfile is not automatically deleted when closed; A program shall call remove to delete this file once closed.

Types

type File added in v0.11.0

type File struct {
	// This is not part of the original struct but it is needed for internal
	// calls in Go.
	OsFile *os.File
}

File represents the definition has been translated from the original definition for __sFILE, which is an alias for FILE. Not all of the attributes have been translated. They should be turned on as needed.

func Fopen added in v0.9.0

func Fopen(filePath, mode []byte) *File

Fopen handles fopen().

Opens the file whose name is specified in the parameter filePath and associates it with a stream that can be identified in future operations by the File pointer returned.

The operations that are allowed on the stream and how these are performed are defined by the mode parameter.

The returned pointer can be disassociated from the file by calling fclose() or freopen(). All opened files are automatically closed on normal program termination.

func NewFile added in v0.11.0

func NewFile(f *os.File) *File

NewFile creates a File pointer from a Go file pointer.

func Tmpfile added in v0.11.0

func Tmpfile() *File

Tmpfile handles tmpfile().

Creates a temporary binary file, open for update ("wb+" mode, see fopen for details) with a filename guaranteed to be different from any other existing file.

The temporary file created is automatically deleted when the stream is closed (fclose) or when the program terminates normally. If the program terminates abnormally, whether the file is deleted depends on the specific system and library implementation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL