-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplace.h
More file actions
44 lines (35 loc) · 1.24 KB
/
Copy pathreplace.h
File metadata and controls
44 lines (35 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef REPLACE_H_
#define REPLACE_H_
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
/* Размер страницы памяти */
#define REPLACE_PAGE_SIZE sysconf(_SC_PAGESIZE)
/* Успешно прочитана строка */
#define REPLACE_SUCCESS_RETVAL 0
/* Не удалось выделить память */
#define REPLACE_NOT_ENOUGH_MEMORY 1
/* Несуществующий указатель на строку */
#define REPLACE_INVALID_POINTER 2
/* Пустой шаблон заменяемой подстроки */
#define REPLACE_EMPTY_PATTERN 3
/* Обработчик функции replace() */
#define REPLACE_HANDLER(id) { \
switch(id) { \
case REPLACE_SUCCESS_RETVAL: \
break; \
case REPLACE_NOT_ENOUGH_MEMORY: \
fprintf(stderr, "failed to allocate memory\n"); \
exit(id); \
case REPLACE_INVALID_POINTER: \
fprintf(stderr, "invalid pointer\n"); \
exit(id); \
case REPLACE_EMPTY_PATTERN: \
fprintf(stderr, "pattern is empty\n"); \
exit(id); \
} \
}
/* Замена одной строки на другую */
int replace(char** text, char* pattern, char* target);
#endif