Main Page Modules Data Structures File List Data Fields Globals Related Pages

# lib/misc.c File Reference

More...

`#include "system.h"`
`#include "rpmio_internal.h"`
`#include <rpmurl.h>`
`#include <rpmmacro.h>`
`#include <rpmlib.h>`
`#include "misc.h"`
`#include "debug.h"`

Go to the source code of this file.

## Functions

rpmRC | rpmMkdirPath (const char *dpath, const char *dname)
| Create directory if it does not exist, and make sure path is writable. More...
char ** | splitString (const char *str, int length, char sep)
| Split string into fields separated by a character. More...
void | freeSplitString (char **list)
| Free split string argv array. More...
int | doputenv (const char *str)
| Like the libc function, but malloc()'s the space needed. More...
int | dosetenv (const char *name, const char *value, int overwrite)
| Like the libc function, but malloc()'s the space needed. More...
int | makeTempFile (const char *prefix, const char **fnptr, FD_t *fdptr)
| Return file handle for a temporaray file. More...
char * | currentDirectory (void)
| Return (malloc'd) current working directory. More...
int | myGlobPatternP (const char *patternURL)
int | glob_error (const char *foo, int bar)
int | rpmGlob (const char *patterns, int *argcPtr, const char ***argvPtr)
int | rpmHeaderGetEntry (Header h, int_32 tag, int_32 *type, void **p, int_32 *c)

## Variables

int | _debug = 0
const char * | RPMVERSION = VERSION

## Detailed Description

Definition in file misc.c.

## Function Documentation

char* currentDirectory | ( | void |  | ) |

Return (malloc'd) current working directory.

Returns:
  current working directory (malloc'ed)

Definition at line 228 of file misc.c.

References errno, xmalloc, and xrealloc.

int doputenv | ( | const char * | str | ) |

Like the libc function, but malloc()'s the space needed.

Parameters:

  str | "name=value" string

Returns:
  0 on success

Definition at line 102 of file misc.c.

References xmalloc.

int dosetenv | ( | const char * | name,
|  | const char * | value,
|  | int | overwrite
| ) |

Like the libc function, but malloc()'s the space needed.

Parameters:

  name | variable name
  value | variable value
  overwrite | should an existing variable be changed?

Returns:
  0 on success

Definition at line 112 of file misc.c.

References getenv, stpcpy, and xmalloc.

void freeSplitString | ( | char ** | list | ) |

Free split string argv array.

Parameters:

  list | argv array

Definition at line 94 of file misc.c.

References _free.

int glob_error | ( | const char * | foo,
|  | int | bar
| ) | `[static]`

| Definition at line 281 of file misc.c. Referenced by rpmGlob.

int makeTempFile | ( | const char * | prefix,
|  | const char ** | fnptr,
|  | FD_t * | fdptr
| ) |

Return file handle for a temporaray file.

A unique temporaray file path will be generated using rpmGenPath(prefix, "%{_tmppath}/", "rpm-tmp.XXXXX") where "XXXXXX" is filled in using rand(3). The file is opened, and the link count and (dev,ino) location are verified after opening. The file name and the open file handle are returned.

Parameters:

  prefix | leading part of temp file path

Return values:

  fnptr | temp file name (or NULL)
  fdptr | temp file handle

Returns:
  0 on success

Definition at line 124 of file misc.c.

References _, _free, errno, Fclose, Ferror, Fileno, Fopen, rpmGenPath, rpmioMkpath, S_ISLNK, URL_IS_DASH, URL_IS_HTTP, URL_IS_PATH, URL_IS_UNKNOWN, and urlPath.

int myGlobPatternP | ( | const char * | patternURL | ) |

| Definition at line 248 of file misc.c. References urlPath.

int rpmGlob | ( | const char * | patterns,
|  | int * | argcPtr,
|  | const char *** | argvPtr
| ) |

| Definition at line 286 of file misc.c. References _free, Glob, glob_error, Globfree, myGlobPatternP, poptParseArgvString, URL_IS_DASH, URL_IS_FTP, URL_IS_HTTP, URL_IS_PATH, URL_IS_UNKNOWN, urlPath, xmalloc, xrealloc, and xstrdup.

rpmRC rpmMkdirPath | ( | const char * | dpath,
|  | const char * | dname
| ) |

Create directory if it does not exist, and make sure path is writable.

Note:
  This will only create last component of directory path.

Parameters:

  dpath | directory path
  dname | directory use string

Returns:
  rpmRC return code

Definition at line 24 of file misc.c.

References _, Access, errno, Mkdir, rpmRC, RPMRC_FAIL, RPMRC_OK, Stat, URL_IS_DASH, URL_IS_FTP, URL_IS_HTTP, URL_IS_PATH, URL_IS_UNKNOWN, urlPath, and W_OK.

char** splitString | ( | const char * | str,
|  | int | length,
|  | char | sep
| ) |

Split string into fields separated by a character.

Parameters:

  str | string
  length | length of string
  sep | separator character

Returns:
  (malloc'd) argv array

Definition at line 57 of file misc.c.

References xmalloc.

## Variable Documentation

int _debug = 0`[static]`

| Definition at line 8 of file misc.c.

const char* RPMVERSION = VERSION

| Definition at line 11 of file misc.c.