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