auth/credentials: don't ignore "client use kerberos" and --use-kerberos for machine...
[Samba.git] / examples / libsmbclient / testwrite.c
blob0e728e058636790b9d6e97527c821ae36e0efb69
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 p = fgets(buffer, sizeof(buffer), stdin);
26 if (p == NULL) {
27 fprintf(stderr, "failed to read from stdin\n");
28 return 1;
32 for (;;)
34 fprintf(stdout, "\nPath: ");
35 *path = '\0';
36 p = fgets(path, sizeof(path) - 1, stdin);
37 if (p == NULL) {
38 fprintf(stderr, "failed to read from stdin\n");
39 return 1;
41 if (strlen(path) == 0)
43 return 0;
46 p = path + strlen(path) - 1;
47 if (*p == '\n')
49 *p = '\0';
52 if ((fd = smbc_open(path, O_WRONLY | O_CREAT | O_TRUNC, 0)) < 0)
54 perror("smbc_open");
55 continue;
58 snprintf(buffer, sizeof(buffer), "%s", "Hello world\n");
60 ret = smbc_write(fd, buffer, strlen(buffer));
61 savedErrno = errno;
62 smbc_close(fd);
64 if (ret < 0)
66 errno = savedErrno;
67 perror("write");
71 return 0;