#include #include #include #include #include #include #include #include #include static void get_auth_data_fn(const char * pServer, const char * pShare, char * pWorkgroup, int maxLenWorkgroup, char * pUsername, int maxLenUsername, char * pPassword, int maxLenPassword) { (void)pServer; (void)pShare; strncpy(pWorkgroup, "", (size_t)maxLenWorkgroup - 1); strncpy(pUsername, "", (size_t)maxLenUsername - 1); strncpy(pPassword, "", (size_t)maxLenPassword - 1); return; } void print_stat_real(const char *prefix, const struct stat *st) { char mtime[32], Ctime[32], atime[32]; strncpy(mtime, ctime(&st->st_mtime), sizeof(mtime)); strncpy(Ctime, ctime(&st->st_ctime), sizeof(Ctime)); strncpy(atime, ctime(&st->st_atime), sizeof(atime)); mtime[strlen(mtime)-1] = '\0'; Ctime[strlen(Ctime)-1] = '\0'; atime[strlen(atime)-1] = '\0'; printf("%-10s: mtime=%s ctime=%s atime=%s\n", prefix, mtime, Ctime, atime); } void print_stat(const char* path, int fd) { struct stat st; if (smbc_stat(path, &st) == 0) print_stat_real("stat", &st); else printf("stat(%s): %s\n", path, strerror(errno)); if (fd != -1) { if (smbc_fstat(fd, &st) == 0) print_stat_real("fstat", &st); else printf("fstat(%d): %s\n", fd, strerror(errno)); } } int main(void) { const int debug = 0; const char path[2048] = "smb://10.10.10.6/all-homes/joerg/test"; smbc_init(get_auth_data_fn, debug); const time_t now = time(NULL); printf("Current time: %s", ctime(&now)); int fd = smbc_open(path, O_WRONLY | O_TRUNC | O_CREAT, 0666); if (fd < 0) { perror("smbc_open new"); return 1; } puts("open succeed"); print_stat(path, fd); struct timeval tv[2]; tv[0].tv_sec = now; tv[0].tv_usec = 0; tv[1].tv_sec = now - 16; tv[1].tv_usec = 0; if (smbc_utimes(path, tv) != 0) { perror("utimes"); goto end; } puts("utimes succeed"); print_stat(path, fd); char buffer[2048]; strncpy(buffer, "Hello world\n", sizeof(buffer)); if (smbc_write(fd, buffer, strlen(buffer)) < 0) { perror("write"); goto end; } puts("write succeed"); print_stat(path, fd); end: smbc_close(fd); puts("close succeed"); print_stat(path, -1); return 0; }