Line | |
---|
1 | #include <sys/types.h>
|
---|
2 | #include <stdio.h>
|
---|
3 | #include <unistd.h>
|
---|
4 | #include <string.h>
|
---|
5 | #include <time.h>
|
---|
6 | #include <errno.h>
|
---|
7 | #include <libsmbclient.h>
|
---|
8 | #include "get_auth_data_fn.h"
|
---|
9 |
|
---|
10 |
|
---|
11 | int main(int argc, char * argv[])
|
---|
12 | {
|
---|
13 | int i;
|
---|
14 | int fd;
|
---|
15 | int ret;
|
---|
16 | int debug = 0;
|
---|
17 | int mode = 0666;
|
---|
18 | int savedErrno;
|
---|
19 | char buffer[2048];
|
---|
20 | char path[2048];
|
---|
21 | char * p;
|
---|
22 | time_t t0;
|
---|
23 | time_t t1;
|
---|
24 | struct stat st;
|
---|
25 |
|
---|
26 | smbc_init(get_auth_data_fn, debug);
|
---|
27 |
|
---|
28 | printf("CAUTION: This program will overwrite a file. "
|
---|
29 | "Press ENTER to continue.");
|
---|
30 | fgets(buffer, sizeof(buffer), stdin);
|
---|
31 |
|
---|
32 |
|
---|
33 | for (;;)
|
---|
34 | {
|
---|
35 | fprintf(stdout, "\nPath: ");
|
---|
36 | *path = '\0';
|
---|
37 | fgets(path, sizeof(path) - 1, stdin);
|
---|
38 | if (strlen(path) == 0)
|
---|
39 | {
|
---|
40 | return 0;
|
---|
41 | }
|
---|
42 |
|
---|
43 | p = path + strlen(path) - 1;
|
---|
44 | if (*p == '\n')
|
---|
45 | {
|
---|
46 | *p = '\0';
|
---|
47 | }
|
---|
48 |
|
---|
49 | if ((fd = smbc_open(path, O_WRONLY | O_CREAT | O_TRUNC, 0)) < 0)
|
---|
50 | {
|
---|
51 | perror("smbc_open");
|
---|
52 | continue;
|
---|
53 | }
|
---|
54 |
|
---|
55 | strcpy(buffer, "Hello world\n");
|
---|
56 |
|
---|
57 | ret = smbc_write(fd, buffer, strlen(buffer));
|
---|
58 | savedErrno = errno;
|
---|
59 | smbc_close(fd);
|
---|
60 |
|
---|
61 | if (ret < 0)
|
---|
62 | {
|
---|
63 | errno = savedErrno;
|
---|
64 | perror("write");
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | return 0;
|
---|
69 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.