~rdoering/ubuntu/karmic/erlang/fix-535090

« back to all changes in this revision

Viewing changes to erts/emulator/drivers/win32/win_efile.c

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-02-15 16:42:52 UTC
  • mfrom: (3.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090215164252-q5x4rcf8a5pbesb1
Tags: 1:12.b.5-dfsg-2
Upload to unstable after lenny is released.

Show diffs side-by-side

added added

removed removed

Lines of Context:
659
659
char* name;                     /* Name of directory to open. */
660
660
int flags;                      /* Flags to use for opening. */
661
661
int* pfd;                       /* Where to store the file descriptor. */
662
 
off_t* pSize;                   /* Where to store the size of the file. */
 
662
Sint64* pSize;                  /* Where to store the size of the file. */
663
663
{
664
664
    BY_HANDLE_FILE_INFORMATION fileInfo; /* File information from a handle. */
665
665
    HANDLE fd;                  /* Handle to open file. */
720
720
    if (!GetFileInformationByHandle(fd, &fileInfo))
721
721
        return set_error(errInfo);
722
722
    *pfd = (int) fd;
723
 
    *pSize = fileInfo.nFileSizeLow;
 
723
    if (pSize) {
 
724
        *pSize = (Sint64)
 
725
            (((Uint64)fileInfo.nFileSizeHigh << 32) | 
 
726
             (Uint64)fileInfo.nFileSizeLow);
 
727
    }
724
728
    return 1;
725
729
}
726
730
 
1025
1029
int fd;                         /* File descriptor to write to. */
1026
1030
char* buf;                      /* Buffer to write. */
1027
1031
size_t count;                   /* Number of bytes to write. */
1028
 
off_t offset;                   /* where to write it */
 
1032
Sint64 offset;                  /* where to write it */
1029
1033
{
1030
 
    int res, location;
1031
 
 
1032
 
    if ((res = efile_seek(errInfo, fd, offset, 
1033
 
                          EFILE_SEEK_SET, &location)))
 
1034
    int res  = efile_seek(errInfo, fd, offset, EFILE_SEEK_SET, NULL);
 
1035
    if (res) {
1034
1036
        return efile_write(errInfo, EFILE_MODE_WRITE, fd, buf, count);
1035
 
    else
 
1037
    } else {
1036
1038
        return res;
 
1039
    }
1037
1040
}
1038
1041
 
1039
1042
/* position and read/write as a single atomic op */
1041
1044
efile_pread(errInfo, fd, offset, buf, count, pBytesRead)
1042
1045
Efile_error* errInfo;           /* Where to return error codes. */
1043
1046
int fd;                         /* File descriptor to read from. */
1044
 
off_t offset;                   /* Offset in bytes from BOF. */
 
1047
Sint64 offset;                  /* Offset in bytes from BOF. */
1045
1048
char* buf;                      /* Buffer to read into. */
1046
1049
size_t count;                   /* Number of bytes to read. */
1047
1050
size_t* pBytesRead;             /* Where to return number of bytes read. */
1048
1051
{
1049
 
    int res, location;
1050
 
 
1051
 
    if ((res = efile_seek(errInfo, fd, offset, EFILE_SEEK_SET, 
1052
 
                          &location)))
 
1052
    int res = efile_seek(errInfo, fd, offset, EFILE_SEEK_SET, NULL);
 
1053
    if (res) {
1053
1054
        return efile_read(errInfo, EFILE_MODE_READ, fd, buf, count, pBytesRead);
1054
 
    else
 
1055
    } else {
1055
1056
        return res;
 
1057
    }
1056
1058
}
1057
1059
 
1058
1060
 
1133
1135
efile_seek(errInfo, fd, offset, origin, new_location)
1134
1136
Efile_error* errInfo;           /* Where to return error codes. */
1135
1137
int fd;                         /* File descriptor to do the seek on. */
1136
 
off_t offset;                   /* Offset in bytes from the given origin. */
 
1138
Sint64 offset;                  /* Offset in bytes from the given origin. */
1137
1139
int origin;                     /* Origin of seek (SEEK_SET, SEEK_CUR,
1138
1140
                                 * SEEK_END).
1139
1141
                                 */
1140
 
off_t* new_location;            /* Resulting new location in file. */
 
1142
Sint64* new_location;           /* Resulting new location in file. */
1141
1143
{
1142
 
    DWORD result;
1143
 
 
 
1144
    LARGE_INTEGER off, new_loc;
 
1145
    
1144
1146
    switch (origin) {
1145
1147
    case EFILE_SEEK_SET: origin = FILE_BEGIN; break;
1146
1148
    case EFILE_SEEK_CUR: origin = FILE_CURRENT; break;
1150
1152
        check_error(-1, errInfo);
1151
1153
        break;
1152
1154
    }
1153
 
 
1154
 
    result = SetFilePointer((HANDLE) fd, offset, NULL, origin);
1155
 
    if (result == (DWORD) -1)
 
1155
    
 
1156
    off.QuadPart = offset;
 
1157
    if (! SetFilePointerEx((HANDLE) fd, off,
 
1158
        new_location ? &new_loc : NULL, origin)) {
1156
1159
        return set_error(errInfo);
1157
 
    DEBUGF(("efile_seek(offset=%d, origin+%d) -> %d\n", offset, origin, result));
1158
 
    *new_location = (unsigned) result;
 
1160
    }
 
1161
    if (new_location) {
 
1162
        *new_location = new_loc.QuadPart;
 
1163
        DEBUGF(("efile_seek(offset=%ld, origin=%d) -> %ld\n", 
 
1164
                (long) offset, origin, (long) *new_location));
 
1165
    } else {
 
1166
        DEBUGF(("efile_seek(offset=%ld, origin=%d)\n", (long) offset, origin));
 
1167
    }
1159
1168
    return 1;
1160
1169
}
1161
1170