2 * uxsftp.c: the Unix-specific parts of PSFTP.
15 * In PSFTP our selects are synchronous, so these functions are
18 int uxsel_input_add(int fd
, int rwx
) { return 0; }
19 void uxsel_input_remove(int id
) { }
21 char *x_get_default(const char *key
)
23 return NULL
; /* this is a stub */
26 void platform_get_x11_auth(char *display
, int *protocol
,
27 unsigned char *data
, int *datalen
)
29 /* Do nothing, therefore no auth. */
33 * Default settings that are specific to PSFTP.
35 char *platform_default_s(const char *name
)
37 if (!strcmp(name
, "UserName")) {
39 * Remote login username will default to the local username.
43 char *user
, *ret
= NULL
;
46 * First, find who we think we are using getlogin. If this
47 * agrees with our uid, we'll go along with it. This should
48 * allow sharing of uids between several login names whilst
49 * coping correctly with people who have su'ed.
57 if (p
&& p
->pw_uid
== uid
) {
59 * The result of getlogin() really does correspond to
65 * If that didn't work, for whatever reason, we'll do
66 * the simpler version: look up our uid in the password
67 * file and map it straight to a name.
79 int platform_default_i(const char *name
, int def
)
84 FontSpec
platform_default_fontspec(const char *name
)
91 Filename
platform_default_filename(const char *name
)
94 if (!strcmp(name
, "LogFileName"))
95 strcpy(ret
.path
, "putty.log");
102 * Set local current directory. Returns NULL on success, or else an
103 * error message which must be freed after printing.
105 char *psftp_lcd(char *dir
)
108 return dupprintf("%s: chdir: %s", dir
, strerror(errno
));
114 * Get local current directory. Returns a string which must be
117 char *psftp_getcwd(void)
122 buffer
= snewn(size
, char);
124 ret
= getcwd(buffer
, size
);
127 if (errno
!= ERANGE
) {
129 return dupprintf("[cwd unavailable: %s]", strerror(errno
));
132 * Otherwise, ERANGE was returned, meaning the buffer
136 buffer
= sresize(buffer
, size
, char);
141 * Wait for some network data and process it.
143 int ssh_sftp_loop_iteration(void)
145 fd_set rset
, wset
, xset
;
146 int i
, fdcount
, fdsize
, *fdlist
;
147 int fd
, fdstate
, rwx
, ret
, maxfd
;
150 fdcount
= fdsize
= 0;
152 /* Count the currently active fds. */
154 for (fd
= first_fd(&fdstate
, &rwx
); fd
>= 0;
155 fd
= next_fd(&fdstate
, &rwx
)) i
++;
158 return -1; /* doom */
160 /* Expand the fdlist buffer if necessary. */
163 fdlist
= sresize(fdlist
, fdsize
, int);
172 * Add all currently open fds to the select sets, and store
173 * them in fdlist as well.
176 for (fd
= first_fd(&fdstate
, &rwx
); fd
>= 0;
177 fd
= next_fd(&fdstate
, &rwx
)) {
178 fdlist
[fdcount
++] = fd
;
180 FD_SET_MAX(fd
, maxfd
, rset
);
182 FD_SET_MAX(fd
, maxfd
, wset
);
184 FD_SET_MAX(fd
, maxfd
, xset
);
188 ret
= select(maxfd
, &rset
, &wset
, &xset
, NULL
);
189 } while (ret
< 0 && errno
== EINTR
);
196 for (i
= 0; i
< fdcount
; i
++) {
199 * We must process exceptional notifications before
200 * ordinary readability ones, or we may go straight
201 * past the urgent marker.
203 if (FD_ISSET(fd
, &xset
))
204 select_result(fd
, 4);
205 if (FD_ISSET(fd
, &rset
))
206 select_result(fd
, 1);
207 if (FD_ISSET(fd
, &wset
))
208 select_result(fd
, 2);
217 * Main program: do platform-specific initialisation and then call
220 int main(int argc
, char *argv
[])
223 return psftp_main(argc
, argv
);