Greenbone Vulnerability Management Libraries: util/fileutils.c File Reference

Greenbone Vulnerability Management Libraries 23.1.2

Macros | Functions
fileutils.c File Reference

File utilities. More...

`#include "fileutils.h"`
`#include <errno.h>`
`#include <gio/gio.h>`
`#include <glib/gstdio.h>`
`#include <glib/gtypes.h>`
`#include <string.h>`
`#include <sys/stat.h>`
`#include <time.h>`

Go to the source code of this file.

## Macros
#define | _GNU_SOURCE
#define | G_LOG_DOMAIN "libgvm util"
| GLib logging domain.

## Functions
int | gvm_file_check_is_dir (const char *name)
| Checks whether a file is a directory or not.
int | gvm_file_exists (const char *name)
| Checks whether a file or directory exists.
int | gvm_file_is_executable (const char *name)
| Checks whether a file or directory exists and is executable.
int | gvm_file_is_readable (const char *name)
| Checks whether a file or directory exists and is readable.
int | gvm_file_remove_recurse (const gchar *pathname)
| Recursively removes files and directories.
gboolean | gvm_file_copy (const gchar *source_file, const gchar *dest_file)
| Copies a source file into a destination file.
gboolean | gvm_file_move (const gchar *source_file, const gchar *dest_file)
| Moves a source file into a destination file.
char * | gvm_file_as_base64 (const char *path)
| Get the content of a file in base64 format.
gchar * | gvm_export_file_name (const char *fname_format, const char *username, const char *type, const char *uuid, const char *creation_iso_time, const char *modification_iso_time, const char *name, const char *format_name)
| Generates a file name for exporting.

## Detailed Description

File utilities.

## Macro Definition Documentation

## ◆ _GNU_SOURCE

#define _GNU_SOURCE

## ◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN "libgvm util"

GLib logging domain.

## Function Documentation

## ◆ gvm_export_file_name()

gchar * gvm_export_file_name | ( | const char * | fname_format,
|  | const char * | username,
|  | const char * | type,
|  | const char * | uuid,
|  | const char * | creation_iso_time,
|  | const char * | modification_iso_time,
|  | const char * | name,
|  | const char * | format_name )

Generates a file name for exporting.

Parameters

  [in] | fname_format | Format string.
  [in] | username | Current user name.
  [in] | type | Type of resource.
  [in] | uuid | UUID of resource.
  [in] | creation_iso_time | Creation time of resource in ISO format.
  [in] | modification_iso_time | Modification time of resource (ISO).
  [in] | name | Name of resource.
  [in] | format_name | Name of format plugin.

Returns
  The file name.

## ◆ gvm_file_as_base64()

char * gvm_file_as_base64 | ( | const char * | path | ) |

Get the content of a file in base64 format.

Parameters

  [in] | path | Path to file.

Returns
  Allocated nul-terminated string, NULL otherwise.

## ◆ gvm_file_check_is_dir()

int gvm_file_check_is_dir | ( | const char * | name | ) |

Checks whether a file is a directory or not.

This is a replacement for the g_file_test functionality which is reported to be unreliable under certain circumstances, for example if this application and glib are compiled with a different libc.

Symbolic links are not followed.

Parameters

  [in] | name | Name of file or directory.

Returns
  1 if parameter is directory, 0 if it is not, -1 if it does not exist or could not be accessed.

## ◆ gvm_file_copy()

gboolean gvm_file_copy | ( | const gchar * | source_file,
|  | const gchar * | dest_file )

Copies a source file into a destination file.

If the destination file does exist already, it will be overwritten.

Parameters

  [in] | source_file | Source file name.
  [in] | dest_file | Destination file name.

Returns
  TRUE if successful, FALSE otherwise.

## ◆ gvm_file_exists()

int gvm_file_exists | ( | const char * | name | ) |

Checks whether a file or directory exists.

Unlike g_file_test this checks the permissions based on the effective UID and GID instead of the real one.

Symbolic links are followed.

Parameters

  [in] | name | Name of file or directory.

Returns
  1 if file exists, 0 if it is not.

## ◆ gvm_file_is_executable()

int gvm_file_is_executable | ( | const char * | name | ) |

Checks whether a file or directory exists and is executable.

Unlike g_file_test this checks the permissions based on the effective UID and GID instead of the real one.

Symbolic links are followed.

Parameters

  [in] | name | Name of file or directory.

Returns
  1 if file is executable, 0 if it is not.

## ◆ gvm_file_is_readable()

int gvm_file_is_readable | ( | const char * | name | ) |

Checks whether a file or directory exists and is readable.

Unlike g_file_test this checks the permissions based on the effective UID and GID instead of the real one.

Symbolic links are followed.

Parameters

  [in] | name | Name of file or directory.

Returns
  1 if file is readable, 0 if it is not.

## ◆ gvm_file_move()

gboolean gvm_file_move | ( | const gchar * | source_file,
|  | const gchar * | dest_file )

Moves a source file into a destination file.

If the destination file does exist already, it will be overwritten.

Parameters

  [in] | source_file | Source file name.
  [in] | dest_file | Destination file name.

Returns
  TRUE if successful, FALSE otherwise.

## ◆ gvm_file_remove_recurse()

int gvm_file_remove_recurse | ( | const gchar * | pathname | ) |

Recursively removes files and directories.

This function will recursively call itself to delete a path and any contents of this path.

Parameters

  [in] | pathname | The name of the file to be deleted from the filesystem.

Returns
  0 if the name was successfully deleted, -1 if an error occurred.