STASIS
A pipeline delivery generator
Loading...
Searching...
No Matches
relocation.h File Reference
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <linux/limits.h>
#include <unistd.h>
Include dependency graph for relocation.h:

Go to the source code of this file.

Macros

#define REPLACE_TRUNCATE_AFTER_MATCH   1
 

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:109
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));
strncpy(str, "This are a test.", str_maxlen - 1);
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