Module ggstd::os

source ·

Modules

  • Package user allows user account lookups by name or id.

Structs

  • TempDir contains information about a created temporary directory and will remove the directory recursively after the object goes out of scope. This is a convenience structure over mkdir_temp results.
  • TempFile contains information about a created temporary file and will remove the temporary file after the object goes out of scope. This is a convenience structure over create_temp results.

Functions

  • Create creates or truncates the named file. If the file already exists, it is truncated. If the file does not exist, it is created.
  • create_temp creates a new temporary file in the directory dir, opens the file for reading and writing, and returns TempFile structure that contains the opened file and the path to it. The filename is generated by taking pattern and adding a random string to the end. If pattern includes a “”, the random string replaces the last “”. If dir is the empty string, create_temp uses the default directory for temporary files, as returned by temp_dir. Multiple programs or goroutines calling create_temp simultaneously will not choose the same file. It is the caller’s responsibility to remove the file when it is no longer needed. TempFile can be used as a more convenient interface for creating and automatically removing a temporary file.
  • get_uid returns the numeric user id of the caller.
  • mkdir_temp creates a new temporary directory in the directory dir and returns the pathname of the new directory. The new directory’s name is generated by adding a random string to the end of pattern. If pattern includes a “”, the random string replaces the last “” instead. If dir is the empty string, mkdir_temp uses the default directory for temporary files, as returned by temp_dir. Multiple programs or goroutines calling mkdir_temp simultaneously will not choose the same directory. It is the caller’s responsibility to remove the directory when it is no longer needed. TempDir can be used as a more convenient interface for creating and automatically removing a temporary directory.
  • Open opens the named file for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDONLY.
  • read_file reads the named file and returns the contents.
  • temp_dir returns the default directory to use for temporary files.