Skip to content

Commit ff96264

Browse files
committed
making lseek explicitly adjust file offset.
1 parent 946ed7d commit ff96264

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

contrib/win32/openssh/config.h.vs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,9 +1664,6 @@
16641664

16651665
#define BROKEN_SYS_TERMIO_H
16661666

1667-
#define strerror strerror_win32
1668-
1669-
#define strerror strerror_win32
16701667

16711668
// PRAGMA SYS PORT
16721669
#define WITH_OPENSSL 1

contrib/win32/win32compat/fileio.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ createFile_flags_setup(int flags, int mode, struct createFile_flags* cf_flags) {
223223
if (c_s_flags & O_EXCL)
224224
cf_flags->dwCreationDisposition = CREATE_NEW;
225225
else
226-
cf_flags->dwCreationDisposition = OPEN_ALWAYS;
227-
}
226+
cf_flags->dwCreationDisposition = CREATE_ALWAYS;
227+
}
228228

229229
if (c_s_flags & O_APPEND)
230230
cf_flags->dwDesiredAccess = FILE_APPEND_DATA;
@@ -301,7 +301,7 @@ VOID CALLBACK ReadCompletionRoutine(
301301
/* initiate an async read */
302302
/* TODO: make this a void func, store error in context */
303303
int
304-
fileio_ReadFileEx(struct w32_io* pio) {
304+
fileio_ReadFileEx(struct w32_io* pio, unsigned int bytes_requested) {
305305
debug2("ReadFileEx io:%p", pio);
306306

307307
if (pio->read_details.buf == NULL) {
@@ -311,9 +311,13 @@ fileio_ReadFileEx(struct w32_io* pio) {
311311
debug2("ReadFileEx - ERROR: %d, io:%p", errno, pio);
312312
return -1;
313313
}
314-
pio->read_details.buf_size = READ_BUFFER_SIZE;
315314
}
316315

316+
if (FILETYPE(pio) == FILE_TYPE_DISK)
317+
pio->read_details.buf_size = min(bytes_requested, READ_BUFFER_SIZE);
318+
else
319+
pio->read_details.buf_size = READ_BUFFER_SIZE;
320+
317321
if (ReadFileEx(WINHANDLE(pio), pio->read_details.buf, pio->read_details.buf_size,
318322
&pio->read_overlapped, &ReadCompletionRoutine))
319323
pio->read_details.pending = TRUE;
@@ -353,7 +357,7 @@ fileio_read(struct w32_io* pio, void *dst, unsigned int max) {
353357
return -1;
354358
}
355359
else {
356-
if (-1 == fileio_ReadFileEx(pio)) {
360+
if (-1 == fileio_ReadFileEx(pio, max)) {
357361
if ((FILETYPE(pio) == FILE_TYPE_PIPE)
358362
&& (errno == ERROR_BROKEN_PIPE)) {
359363
/* write end of the pipe closed */
@@ -560,8 +564,8 @@ fileio_lseek(struct w32_io* pio, long offset, int origin) {
560564
return -1;
561565
}
562566

563-
//NO-OP as we automatically move file pointer in async io callbacks for files
564-
//assert current postion in overlapped struct
567+
pio->read_overlapped.Offset = offset;
568+
pio->write_overlapped.Offset = offset;
565569
return 0;
566570
}
567571

@@ -625,7 +629,7 @@ fileio_on_select(struct w32_io* pio, BOOL rd) {
625629
}
626630
}
627631
else {
628-
if (fileio_ReadFileEx(pio) != 0) {
632+
if (fileio_ReadFileEx(pio, INT_MAX) != 0) {
629633
pio->read_details.error = errno;
630634
errno = 0;
631635
return;

sftp-server.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,7 @@ process_rmdir(u_int32_t id)
13201320
static void
13211321
process_realpath(u_int32_t id)
13221322
{
1323-
char resolvedname[PATH_MAX];
1323+
char resolvedname[PATH_MAX+ 1];
13241324
char *path;
13251325
int r;
13261326
//#ifdef WIN32_FIXME

0 commit comments

Comments
 (0)