dbwrap_cache: Fix dbwrap_cache_validate
[Samba.git] / examples / libsmbclient / testwrite.c
blobb641a08a1ce07164514b43e04f422f4467bf13cf
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 fd;
14 int ret;
15 int debug = 0;
16 int savedErrno;
17 char buffer[2048];
18 char path[2048];
19 char * p;
21 smbc_init(get_auth_data_fn, debug);
23 printf("CAUTION: This program will overwrite a file. "
24 "Press ENTER to continue.");
25 fgets(buffer, sizeof(buffer), stdin);
28 for (;;)
30 fprintf(stdout, "\nPath: ");
31 *path = '\0';
32 fgets(path, sizeof(path) - 1, stdin);
33 if (strlen(path) == 0)
35 return 0;
38 p = path + strlen(path) - 1;
39 if (*p == '\n')
41 *p = '\0';
44 if ((fd = smbc_open(path, O_WRONLY | O_CREAT | O_TRUNC, 0)) < 0)
46 perror("smbc_open");
47 continue;
50 strcpy(buffer, "Hello world\n");
52 ret = smbc_write(fd, buffer, strlen(buffer));
53 savedErrno = errno;
54 smbc_close(fd);
56 if (ret < 0)
58 errno = savedErrno;
59 perror("write");
63 return 0;