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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
#include "system.h"
#include <rpmio_internal.h>
#include <rpmmacro.h>
#include <rpmmessages.h>
#include <popt.h>
#include "debug.h"
static int _debug = 0;
#define HTTPSPATH "https://localhost/rawhide/toad/tput.txt"
#define HTTPPATH "http://localhost/rawhide/toad/tput.txt"
#define FTPPATH "ftp://localhost/home/test/tput.txt"
#define DIRPATH "file://localhost/var/ftp/tput.txt"
static char * httpspath = HTTPSPATH;
static char * httppath = HTTPPATH;
static char * ftppath = FTPPATH;
static char * dirpath = DIRPATH;
static size_t readFile(const char * path)
{
char buf[BUFSIZ];
size_t len = 0;
FD_t fd;
int xx;
buf[0] = '\0';
fprintf(stderr, "===== Fread %s\n", path);
fd = Fopen(path, "r.ufdio");
if (fd != NULL) {
len = Fread(buf, 1, sizeof(buf), fd);
xx = Fclose(fd);
}
if (len > 0)
fwrite(buf, 1, strlen(buf), stderr);
return len;
}
static size_t writeFile(const char * path)
{
char buf[BUFSIZ];
size_t len = 0;
FD_t fd;
int xx;
strcpy(buf, "Hello World!\n");
fprintf(stderr, "===== Fwrite %s\n", path);
fd = Fopen(path, "w.ufdio");
if (fd != NULL) {
len = Fwrite(buf, 1, strlen(buf), fd);
xx = Fclose(fd);
if (xx)
fprintf(stderr, "===> Fclose rc %d\n", xx);
}
if (len > 0)
fwrite(buf, 1, strlen(buf), stderr);
return len;
}
static int unlinkFile(const char * path)
{
fprintf(stderr, "===== Unlink %s\n", path);
return Unlink(path);
}
static void doFile(const char * path)
{
int xx;
fprintf(stderr, "===== %s\n", path);
#if 0
xx = unlink("/home/toad/tput.txt");
xx = unlink("/var/ftp/tput.txt");
xx = unlink("/var/www/html/tput.txt");
#endif
#if 0
xx = unlinkFile(path);
#endif
xx = writeFile(path);
#if 0
xx = readFile(path);
xx = Unlink(path);
xx = unlink("/home/toad/tput.txt");
xx = unlink("/var/ftp/tput.txt");
xx = unlink("/var/www/html/tput.txt");
#endif
}
static struct poptOption optionsTable[] = {
{ "debug", 'd', POPT_ARG_VAL, &_debug, -1, NULL, NULL },
{ "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
N_("debug rpmio I/O"), NULL},
{ "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1,
N_("debug URL cache handling"), NULL},
{ "verbose", 'v', 0, 0, 'v', NULL, NULL },
POPT_AUTOHELP
POPT_TABLEEND
};
int
main(int argc, char *argv[])
{
poptContext optCon = poptGetContext(argv[0], argc, argv, optionsTable, 0);
int rc;
while ((rc = poptGetNextOpt(optCon)) > 0) {
switch (rc) {
case 'v':
rpmIncreaseVerbosity();
break;
default:
break;
}
}
if (_debug) {
rpmIncreaseVerbosity();
rpmIncreaseVerbosity();
}
#if 0
doFile(dirpath);
doFile(ftppath);
#endif
doFile(httppath);
#if 0
doFile(httpspath);
#endif
return 0;
}
|