STASIS
A pipeline delivery generator
Loading...
Searching...
No Matches
relocation.c File Reference
#include "relocation.h"
#include "str.h"
Include dependency graph for relocation.c:

Functions

int replace_text (char *original, const char *target, const char *replacement, unsigned flags)
 
int file_replace_text (const char *filename, const char *target, const char *replacement, unsigned flags)
 

Function Documentation

◆ file_replace_text()

int file_replace_text ( const char * filename,
const char * target,
const char * replacement,
unsigned flags )

Replace target with replacement in filename

if (file_replace_text("/path/to/file.txt", "are", "is")) {
fprintf(stderr, "failed to replace strings in file\n");
exit(1);
}
int file_replace_text(const char *filename, const char *target, const char *replacement, unsigned flags)
Definition relocation.c:110
Parameters
filenamepath to file
targetstring value to replace
replacementstring
flagsREPLACE_TRUNCATE_AFTER_MATCH
Returns
0 on success, -1 on error
Here is the call graph for this function:

◆ replace_text()

int replace_text ( char * original,
const char * target,
const char * replacement,
unsigned flags )

Replace all occurrences of target with replacement in original

size_t str_maxlen = 100;
char *str = calloc(str_maxlen, sizeof(char));
safe_strncpy(str, "This are a test.", str_maxlen);
if (replace_text(str, "are", "is")) {
fprintf(stderr, "string replacement failed\n");
exit(1);
}
// str is: "This is a test."
free(str);
int replace_text(char *original, const char *target, const char *replacement, unsigned flags)
Definition relocation.c:28
Parameters
originalstring to modify
targetstring value to replace
replacementstring value
flagsREPLACE_TRUNCATE_AFTER_MATCH
Returns
0 on success, -1 on error