Re-run make idl.
[Samba/gebeck_regimport.git] / examples / libsmbclient / testwrite.c
blob780f0e95da9de7de2868c26c2a68f8675063a8d6
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"
11 int main(int argc, char * argv[])
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;
26 smbc_init(get_auth_data_fn, debug);
28 printf("CAUTION: This program will overwrite a file. "
29 "Press ENTER to continue.");
30 fgets(buffer, sizeof(buffer), stdin);
33 for (;;)
35 fprintf(stdout, "\nPath: ");
36 *path = '\0';
37 fgets(path, sizeof(path) - 1, stdin);
38 if (strlen(path) == 0)
40 return 0;
43 p = path + strlen(path) - 1;
44 if (*p == '\n')
46 *p = '\0';
49 if ((fd = smbc_open(path, O_WRONLY | O_CREAT | O_TRUNC, 0)) < 0)
51 perror("smbc_open");
52 continue;
55 strcpy(buffer, "Hello world\n");
57 ret = smbc_write(fd, buffer, strlen(buffer));
58 savedErrno = errno;
59 smbc_close(fd);
61 if (ret < 0)
63 errno = savedErrno;
64 perror("write");
68 return 0;