2 * uxsftp.c: the Unix-specific parts of PSFTP and PSCP.
19 * In PSFTP our selects are synchronous, so these functions are
22 int uxsel_input_add(int fd
, int rwx
) { return 0; }
23 void uxsel_input_remove(int id
) { }
25 char *x_get_default(const char *key
)
27 return NULL
; /* this is a stub */
30 void platform_get_x11_auth(char *display
, int *protocol
,
31 unsigned char *data
, int *datalen
)
33 /* Do nothing, therefore no auth. */
37 * Default settings that are specific to PSFTP.
39 char *platform_default_s(const char *name
)
44 int platform_default_i(const char *name
, int def
)
49 FontSpec
platform_default_fontspec(const char *name
)
56 Filename
platform_default_filename(const char *name
)
59 if (!strcmp(name
, "LogFileName"))
60 strcpy(ret
.path
, "putty.log");
67 * Stubs for the GUI feedback mechanism in Windows PSCP.
69 void gui_update_stats(char *name
, unsigned long size
,
70 int percentage
, unsigned long elapsed
,
71 unsigned long done
, unsigned long eta
,
72 unsigned long ratebs
) {}
73 void gui_send_errcount(int list
, int errs
) {}
74 void gui_send_char(int is_stderr
, int c
) {}
75 void gui_enable(char *arg
) {}
79 * Set local current directory. Returns NULL on success, or else an
80 * error message which must be freed after printing.
82 char *psftp_lcd(char *dir
)
85 return dupprintf("%s: chdir: %s", dir
, strerror(errno
));
91 * Get local current directory. Returns a string which must be
94 char *psftp_getcwd(void)
99 buffer
= snewn(size
, char);
101 ret
= getcwd(buffer
, size
);
104 if (errno
!= ERANGE
) {
106 return dupprintf("[cwd unavailable: %s]", strerror(errno
));
109 * Otherwise, ERANGE was returned, meaning the buffer
113 buffer
= sresize(buffer
, size
, char);
121 RFile
*open_existing_file(char *name
, unsigned long *size
,
122 unsigned long *mtime
, unsigned long *atime
)
127 fd
= open(name
, O_RDONLY
);
134 if (size
|| mtime
|| atime
) {
136 if (fstat(fd
, &statbuf
) < 0) {
137 fprintf(stderr
, "%s: stat: %s\n", name
, strerror(errno
));
138 memset(&statbuf
, 0, sizeof(statbuf
));
142 *size
= statbuf
.st_size
;
145 *mtime
= statbuf
.st_mtime
;
148 *atime
= statbuf
.st_atime
;
154 int read_from_file(RFile
*f
, void *buffer
, int length
)
156 return read(f
->fd
, buffer
, length
);
159 void close_rfile(RFile
*f
)
170 WFile
*open_new_file(char *name
)
175 fd
= open(name
, O_CREAT
| O_TRUNC
| O_WRONLY
, 0666);
181 ret
->name
= dupstr(name
);
186 int write_to_file(WFile
*f
, void *buffer
, int length
)
188 char *p
= (char *)buffer
;
191 /* Keep trying until we've really written as much as we can. */
193 int ret
= write(f
->fd
, p
, length
);
209 void set_file_times(WFile
*f
, unsigned long mtime
, unsigned long atime
)
219 /* Closes and frees the WFile */
220 void close_wfile(WFile
*f
)
227 int file_type(char *name
)
231 if (stat(name
, &statbuf
) < 0) {
233 fprintf(stderr
, "%s: stat: %s\n", name
, strerror(errno
));
234 return FILE_TYPE_NONEXISTENT
;
237 if (S_ISREG(statbuf
.st_mode
))
238 return FILE_TYPE_FILE
;
240 if (S_ISDIR(statbuf
.st_mode
))
241 return FILE_TYPE_DIRECTORY
;
243 return FILE_TYPE_WEIRD
;
250 DirHandle
*open_directory(char *name
)
259 ret
= snew(DirHandle
);
264 char *read_filename(DirHandle
*dir
)
269 de
= readdir(dir
->dir
);
272 } while ((de
->d_name
[0] == '.' &&
273 (de
->d_name
[1] == '\0' ||
274 (de
->d_name
[1] == '.' && de
->d_name
[2] == '\0'))));
276 return dupstr(de
->d_name
);
279 void close_directory(DirHandle
*dir
)
285 int test_wildcard(char *name
, int cmdline
)
288 * On Unix, we currently don't support local wildcards at all.
289 * We will have to do so (FIXME) once PSFTP starts implementing
290 * mput, but until then we can assume `cmdline' is always set.
295 if (stat(name
, &statbuf
) < 0)
296 return WCTYPE_NONEXISTENT
;
298 return WCTYPE_FILENAME
;
302 * Actually return matching file names for a local wildcard. FIXME:
303 * we currently don't support this at all.
305 struct WildcardMatcher
{
308 WildcardMatcher
*begin_wildcard_matching(char *name
) { return NULL
; }
309 char *wildcard_get_filename(WildcardMatcher
*dir
) { return NULL
; }
310 void finish_wildcard_matching(WildcardMatcher
*dir
) {}
312 int create_directory(char *name
)
314 return mkdir(name
, 0777) == 0;
317 char *dir_file_cat(char *dir
, char *file
)
319 return dupcat(dir
, "/", file
, NULL
);
323 * Wait for some network data and process it.
325 int ssh_sftp_loop_iteration(void)
327 fd_set rset
, wset
, xset
;
328 int i
, fdcount
, fdsize
, *fdlist
;
329 int fd
, fdstate
, rwx
, ret
, maxfd
;
332 fdcount
= fdsize
= 0;
334 /* Count the currently active fds. */
336 for (fd
= first_fd(&fdstate
, &rwx
); fd
>= 0;
337 fd
= next_fd(&fdstate
, &rwx
)) i
++;
340 return -1; /* doom */
342 /* Expand the fdlist buffer if necessary. */
345 fdlist
= sresize(fdlist
, fdsize
, int);
354 * Add all currently open fds to the select sets, and store
355 * them in fdlist as well.
358 for (fd
= first_fd(&fdstate
, &rwx
); fd
>= 0;
359 fd
= next_fd(&fdstate
, &rwx
)) {
360 fdlist
[fdcount
++] = fd
;
362 FD_SET_MAX(fd
, maxfd
, rset
);
364 FD_SET_MAX(fd
, maxfd
, wset
);
366 FD_SET_MAX(fd
, maxfd
, xset
);
370 ret
= select(maxfd
, &rset
, &wset
, &xset
, NULL
);
371 } while (ret
< 0 && errno
== EINTR
);
378 for (i
= 0; i
< fdcount
; i
++) {
381 * We must process exceptional notifications before
382 * ordinary readability ones, or we may go straight
383 * past the urgent marker.
385 if (FD_ISSET(fd
, &xset
))
386 select_result(fd
, 4);
387 if (FD_ISSET(fd
, &rset
))
388 select_result(fd
, 1);
389 if (FD_ISSET(fd
, &wset
))
390 select_result(fd
, 2);
399 * Main program: do platform-specific initialisation and then call
402 int main(int argc
, char *argv
[])
405 return psftp_main(argc
, argv
);