Skip to content

Commit beb8dc5

Browse files
committed
Remove redundant code in sftp.exe
1 parent 3188167 commit beb8dc5

File tree

3 files changed

+18
-154
lines changed

3 files changed

+18
-154
lines changed

sftp-client.c

Lines changed: 18 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,6 @@
6565

6666
#ifdef WIN32_FIXME
6767

68-
//#include <sys/socket.h>
69-
70-
//#define mkdir(a, b) _mkdir(a)
71-
72-
//#define lstat(PATH, BUF) _stat(PATH, BUF)
73-
74-
/*
75-
* Don't use fstat() function redefined
76-
* in socket.h ported header. It is wrong
77-
* in this context.
78-
*/
79-
80-
//#ifdef fstat
81-
//#undef fstat
82-
//#endif
83-
8468
int glob(const char *pattern, int flags, int (*errfunc)(const char *epath, int eerrno),
8569
glob_t *pglob)
8670
{
@@ -124,39 +108,26 @@
124108
//free(pglob);
125109
}
126110
}
127-
128-
pid_t waitpid(pid_t pid, int *stat_loc, int options)
129-
{
130-
return 0;
131-
}
132-
133-
/*
134-
* Write array of buffers to file descriptor.
135-
*
136-
* fd - file descriptor to write (IN).
137-
* iovec - array of iovec with buffers to send (IN).
138-
* iovecnt - number of buffers in iovec (IN).
139-
*
140-
* RETURNS: Number of bytes written or -1 if error.
141-
*/
142-
111+
112+
/** TODO - Move this to POSIX wrapper**/
113+
/* ??? What if fd is nonblocking ???*/
143114
int writev(int fd, struct iovec *iov, int iovcnt)
144115
{
145-
int written = 0;
116+
int written = 0;
146117

147-
int i = 0;
148-
149-
for (i = 0; i < iovcnt; i++)
150-
{
151-
int ret = write(fd, iov[i].iov_base, iov[i].iov_len);
118+
int i = 0;
152119

153-
if (ret > 0)
154-
{
155-
written += ret;
156-
}
157-
}
158-
159-
return written;
120+
for (i = 0; i < iovcnt; i++)
121+
{
122+
int ret = write(fd, iov[i].iov_base, iov[i].iov_len);
123+
124+
if (ret > 0)
125+
{
126+
written += ret;
127+
}
128+
}
129+
130+
return written;
160131
}
161132

162133
#endif
@@ -1315,16 +1286,9 @@ do_download(struct sftp_conn *conn, const char *remote_path,
13151286
return(-1);
13161287
}
13171288

1318-
#if(0)//def WIN32_FIXME
1319-
1320-
local_fd = _open(local_path,
1321-
O_WRONLY | O_CREAT | O_BINARY | (resume_flag ? 0 : O_TRUNC), mode | S_IWUSR);
1322-
1323-
#else
1324-
local_fd = open(local_path,
1325-
O_WRONLY | O_CREAT | (resume_flag ? 0 : O_TRUNC), mode | S_IWUSR); // PRAGMA:TODO
1289+
local_fd = open(local_path,
1290+
O_WRONLY | O_CREAT | (resume_flag ? 0 : O_TRUNC), mode | S_IWUSR);
13261291

1327-
#endif
13281292

13291293
if (local_fd == -1) {
13301294
error("Couldn't open local file \"%s\" for writing: %s",
@@ -1433,16 +1397,8 @@ do_download(struct sftp_conn *conn, const char *remote_path,
14331397
fatal("Received more data than asked for "
14341398
"%zu > %zu", len, req->len);
14351399
if ((lseek(local_fd, req->offset, SEEK_SET) == -1 ||
1436-
#if(0)//def WIN32_FIXME
1437-
1438-
atomicio(_write, local_fd, data, len) != len) &&
1439-
1440-
#else
1441-
14421400
atomicio(vwrite, local_fd, data, len) != len) &&
14431401

1444-
#endif
1445-
14461402
!write_error) {
14471403
write_errno = errno;
14481404
write_error = 1;
@@ -1556,15 +1512,7 @@ do_download(struct sftp_conn *conn, const char *remote_path,
15561512
}
15571513
#endif
15581514
}
1559-
#if(0)//def WIN32_FIXME
1560-
1561-
_close(local_fd);
1562-
1563-
#else
1564-
15651515
close(local_fd);
1566-
1567-
#endif
15681516
sshbuf_free(msg);
15691517
free(handle);
15701518

@@ -1730,15 +1678,7 @@ do_upload(struct sftp_conn *conn, const char *local_path,
17301678
}
17311679
if (!S_ISREG(sb.st_mode)) {
17321680
error("%s is not a regular file", local_path);
1733-
#if(0)//def WIN32_FIXME
1734-
1735-
_close(local_fd);
1736-
1737-
#else
1738-
17391681
close(local_fd);
1740-
1741-
#endif
17421682
return(-1);
17431683
}
17441684
stat_to_attrib(&sb, &a);
@@ -1789,16 +1729,7 @@ do_upload(struct sftp_conn *conn, const char *local_path,
17891729
handle = get_handle(conn, id, &handle_len,
17901730
"remote open(\"%s\")", remote_path);
17911731
if (handle == NULL) {
1792-
#if(0)//def WIN32_FIXME
1793-
1794-
_close(local_fd);
1795-
1796-
#else
1797-
17981732
close(local_fd);
1799-
1800-
#endif
1801-
18021733
sshbuf_free(msg);
18031734
return -1;
18041735
}
@@ -1824,16 +1755,8 @@ do_upload(struct sftp_conn *conn, const char *local_path,
18241755
if (interrupted || status != SSH2_FX_OK)
18251756
len = 0;
18261757
else do
1827-
#if(0)//def WIN32_FIXME
1828-
1829-
len = _read(local_fd, data, conn->transfer_buflen);
1830-
1831-
#else
1832-
18331758
len = read(local_fd, data, conn->transfer_buflen);
18341759

1835-
#endif
1836-
18371760
while ((len == -1) &&
18381761
(errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
18391762

@@ -1916,16 +1839,7 @@ do_upload(struct sftp_conn *conn, const char *local_path,
19161839
status = SSH2_FX_FAILURE;
19171840
}
19181841

1919-
#if(0)//def WIN32_FIXME
1920-
1921-
if (_close(local_fd) == -1)
1922-
{
1923-
1924-
#else
1925-
19261842
if (close(local_fd) == -1) {
1927-
1928-
#endif
19291843
error("Couldn't close local file \"%s\": %s", local_path,
19301844
strerror(errno));
19311845
status = SSH2_FX_FAILURE;

sftp-common.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@
3131
*/
3232

3333
#ifdef WIN32_FIXME
34-
#undef GSSAPI
35-
#undef KRB5
36-
3734
void strmode(mode_t mode, char *p);
3835
void strmode_from_attrib(unsigned attrib, char *p);
3936
#endif

sftp.c

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,55 +2337,8 @@ main(int argc, char **argv)
23372337

23382338
w32posix_initialize();
23392339

2340-
/* WSHELPinitialize();
2341-
2342-
allocate_standard_descriptor(STDIN_FILENO);
2343-
allocate_standard_descriptor(STDOUT_FILENO);
2344-
allocate_standard_descriptor(STDERR_FILENO);
2345-
2346-
LoadLibrary("libwindbg.dll");*/
2347-
23482340
setvbuf(stdout, NULL, _IONBF, 0);
23492341

2350-
2351-
//sfd_start = 3;
2352-
2353-
/*
2354-
* FIXME. Test.
2355-
*/
2356-
2357-
/*
2358-
2359-
memset(&args, '\0', sizeof(args));
2360-
2361-
args.list = NULL;
2362-
2363-
addargs(&args, "%s", ssh_program);
2364-
2365-
addargs(&args, "-i test_rsa -s [email protected] sftp");
2366-
2367-
connect_to_server(ssh_program, args.list, &in, &out);
2368-
2369-
conn = do_init(in, out, 32768, 64, 0);
2370-
2371-
if (conn == NULL)
2372-
{
2373-
fatal("Couldn't initialise connection to server");
2374-
}
2375-
2376-
//err = interactive_loop(conn, NULL, NULL);
2377-
//do_download(conn, "/home/dzik/unity_run", "c:/tmp/unity_run", NULL, 0);
2378-
2379-
do_ls_dir(conn, "/home/dzik", "", 0);
2380-
2381-
exit(0);
2382-
2383-
*/
2384-
2385-
/*
2386-
* End of test.
2387-
*/
2388-
23892342
#endif
23902343
/* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
23912344
sanitise_stdfd();

0 commit comments

Comments
 (0)