2 * uxsftp.c: the Unix-specific parts of PSFTP and PSCP.
20 * In PSFTP our selects are synchronous, so these functions are
23 int uxsel_input_add(int fd
, int rwx
) { return 0; }
24 void uxsel_input_remove(int id
) { }
26 char *x_get_default(const char *key
)
28 return NULL
; /* this is a stub */
31 void platform_get_x11_auth(char *display
, int *protocol
,
32 unsigned char *data
, int *datalen
)
34 /* Do nothing, therefore no auth. */
38 * Default settings that are specific to PSFTP.
40 char *platform_default_s(const char *name
)
45 int platform_default_i(const char *name
, int def
)
50 FontSpec
platform_default_fontspec(const char *name
)
57 Filename
platform_default_filename(const char *name
)
60 if (!strcmp(name
, "LogFileName"))
61 strcpy(ret
.path
, "putty.log");
68 * Stubs for the GUI feedback mechanism in Windows PSCP.
70 void gui_update_stats(char *name
, unsigned long size
,
71 int percentage
, unsigned long elapsed
,
72 unsigned long done
, unsigned long eta
,
73 unsigned long ratebs
) {}
74 void gui_send_errcount(int list
, int errs
) {}
75 void gui_send_char(int is_stderr
, int c
) {}
76 void gui_enable(char *arg
) {}
80 * Set local current directory. Returns NULL on success, or else an
81 * error message which must be freed after printing.
83 char *psftp_lcd(char *dir
)
86 return dupprintf("%s: chdir: %s", dir
, strerror(errno
));
92 * Get local current directory. Returns a string which must be
95 char *psftp_getcwd(void)
100 buffer
= snewn(size
, char);
102 ret
= getcwd(buffer
, size
);
105 if (errno
!= ERANGE
) {
107 return dupprintf("[cwd unavailable: %s]", strerror(errno
));
110 * Otherwise, ERANGE was returned, meaning the buffer
114 buffer
= sresize(buffer
, size
, char);
122 RFile
*open_existing_file(char *name
, unsigned long *size
,
123 unsigned long *mtime
, unsigned long *atime
)
128 fd
= open(name
, O_RDONLY
);
135 if (size
|| mtime
|| atime
) {
137 if (fstat(fd
, &statbuf
) < 0) {
138 fprintf(stderr
, "%s: stat: %s\n", name
, strerror(errno
));
139 memset(&statbuf
, 0, sizeof(statbuf
));
143 *size
= statbuf
.st_size
;
146 *mtime
= statbuf
.st_mtime
;
149 *atime
= statbuf
.st_atime
;
155 int read_from_file(RFile
*f
, void *buffer
, int length
)
157 return read(f
->fd
, buffer
, length
);
160 void close_rfile(RFile
*f
)
171 WFile
*open_new_file(char *name
)
176 fd
= open(name
, O_CREAT
| O_TRUNC
| O_WRONLY
, 0666);
182 ret
->name
= dupstr(name
);
187 int write_to_file(WFile
*f
, void *buffer
, int length
)
189 char *p
= (char *)buffer
;
192 /* Keep trying until we've really written as much as we can. */
194 int ret
= write(f
->fd
, p
, length
);
210 void set_file_times(WFile
*f
, unsigned long mtime
, unsigned long atime
)
220 /* Closes and frees the WFile */
221 void close_wfile(WFile
*f
)
228 int file_type(char *name
)
232 if (stat(name
, &statbuf
) < 0) {
234 fprintf(stderr
, "%s: stat: %s\n", name
, strerror(errno
));
235 return FILE_TYPE_NONEXISTENT
;
238 if (S_ISREG(statbuf
.st_mode
))
239 return FILE_TYPE_FILE
;
241 if (S_ISDIR(statbuf
.st_mode
))
242 return FILE_TYPE_DIRECTORY
;
244 return FILE_TYPE_WEIRD
;
251 DirHandle
*open_directory(char *name
)
260 ret
= snew(DirHandle
);
265 char *read_filename(DirHandle
*dir
)
270 de
= readdir(dir
->dir
);
273 } while ((de
->d_name
[0] == '.' &&
274 (de
->d_name
[1] == '\0' ||
275 (de
->d_name
[1] == '.' && de
->d_name
[2] == '\0'))));
277 return dupstr(de
->d_name
);
280 void close_directory(DirHandle
*dir
)
286 int test_wildcard(char *name
, int cmdline
)
289 * On Unix, we currently don't support local wildcards at all.
290 * We will have to do so (FIXME) once PSFTP starts implementing
291 * mput, but until then we can assume `cmdline' is always set.
296 if (stat(name
, &statbuf
) < 0)
297 return WCTYPE_NONEXISTENT
;
299 return WCTYPE_FILENAME
;
303 * Actually return matching file names for a local wildcard. FIXME:
304 * we currently don't support this at all.
306 struct WildcardMatcher
{
309 WildcardMatcher
*begin_wildcard_matching(char *name
) { return NULL
; }
310 char *wildcard_get_filename(WildcardMatcher
*dir
) { return NULL
; }
311 void finish_wildcard_matching(WildcardMatcher
*dir
) {}
313 int create_directory(char *name
)
315 return mkdir(name
, 0777) == 0;
318 char *dir_file_cat(char *dir
, char *file
)
320 return dupcat(dir
, "/", file
, NULL
);
324 * Wait for some network data and process it.
326 int ssh_sftp_loop_iteration(void)
328 fd_set rset
, wset
, xset
;
329 int i
, fdcount
, fdsize
, *fdlist
;
330 int fd
, fdstate
, rwx
, ret
, maxfd
;
333 fdcount
= fdsize
= 0;
335 /* Count the currently active fds. */
337 for (fd
= first_fd(&fdstate
, &rwx
); fd
>= 0;
338 fd
= next_fd(&fdstate
, &rwx
)) i
++;
341 return -1; /* doom */
343 /* Expand the fdlist buffer if necessary. */
346 fdlist
= sresize(fdlist
, fdsize
, int);
355 * Add all currently open fds to the select sets, and store
356 * them in fdlist as well.
359 for (fd
= first_fd(&fdstate
, &rwx
); fd
>= 0;
360 fd
= next_fd(&fdstate
, &rwx
)) {
361 fdlist
[fdcount
++] = fd
;
363 FD_SET_MAX(fd
, maxfd
, rset
);
365 FD_SET_MAX(fd
, maxfd
, wset
);
367 FD_SET_MAX(fd
, maxfd
, xset
);
371 ret
= select(maxfd
, &rset
, &wset
, &xset
, NULL
);
372 } while (ret
< 0 && errno
== EINTR
);
379 for (i
= 0; i
< fdcount
; i
++) {
382 * We must process exceptional notifications before
383 * ordinary readability ones, or we may go straight
384 * past the urgent marker.
386 if (FD_ISSET(fd
, &xset
))
387 select_result(fd
, 4);
388 if (FD_ISSET(fd
, &rset
))
389 select_result(fd
, 1);
390 if (FD_ISSET(fd
, &wset
))
391 select_result(fd
, 2);
400 * Main program: do platform-specific initialisation and then call
403 int main(int argc
, char *argv
[])
406 return psftp_main(argc
, argv
);