Changeset 3595


Ignore:
Timestamp:
Oct 3, 2007, 10:57:48 PM (18 years ago)
Author:
bird
Message:

Made it compile on darwin.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kStuff/kRdr/kRdrFile.cpp

    r3588 r3595  
    3232#include <k/kHlpAlloc.h>
    3333#include <k/kHlpString.h>
    34 
    35 #if K_OS == K_OS_OS2
     34#include <k/kErrors.h>
     35
     36#if K_OS == K_OS_DARWIN
     37# include <sys/fcntl.h>
     38# include <sys/mman.h>
     39# include <unistd.h>
     40extern int kHlpSys_open(const char *filename, int flags, int mode); /* negated errno */
     41extern int kHlpSys_close(int fd);
     42extern KSSIZE kHlpSys_read(int fd, void *buf, size_t len); /* negated errno */
     43extern KI64 kHlpSys_lseek(int fd, int whench, KI64); /* negated errno */
     44extern void *kHlpSys_mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off);
     45extern int kHlpSys_mprotect(void *addr, size_t len, int prot);
     46extern int kHlpSys_munmap(void *addr, size_t len);
     47
     48
     49#elif K_OS == K_OS_OS2
    3650# define INCL_ERRORS
    3751# define INCL_BASE
     
    188202    KRDR                Core;
    189203    /** The file handle. */
    190 #if K_OS == K_OS_OS2
     204#if K_OS == K_OS_DARWIN \
     205 || K_OS == K_OS_LINUX \
     206 || K_OS == K_OS_NETBSD \
     207 || K_OS == K_OS_OPENBSD \
     208 || K_OS == K_OS_SOLARIS
     209    int                 File;
     210#elif K_OS == K_OS_OS2
    191211    HFILE               File;
    192212#elif K_OS == K_OS_WINDOWS
     
    373393
    374394/** @copydoc KRDROPS::pfnProtect */
    375 static int      krdrFileProtect(PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments, KBOOL fUnprotectOrProtect)
     395static int krdrFileProtect(PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments, KBOOL fUnprotectOrProtect)
    376396{
    377397    PKRDRFILE        pRdrFile = (PKRDRFILE)pRdr;
     
    556576    pPrep->cb = (pPrep->cb + (cbPage - 1)) & ~(cbPage- 1);
    557577
    558 #if K_OS == K_OS_WINDOWS
     578#if K_OS == K_OS_DARWIN
     579    /** @todo */
     580
     581#elif K_OS == K_OS_WINDOWS
    559582    /*
    560583     * The NT memory mapped file API sucks in a lot of ways. Unless you're actually
     
    803826static KSIZE   krdrFilePageSize(PKRDR pRdr)
    804827{
    805 #if K_OS == K_OS_OS2
     828#if K_OS == K_OS_DARWIN
     829    return 0x1000; /** @todo find some header somewhere... */
     830
     831#elif K_OS == K_OS_OS2
    806832    /* The page size on OS/2 wont change anytime soon. :-) */
    807833    return 0x1000;
     
    829855{
    830856    PKRDRFILE pRdrFile = (PKRDRFILE)pRdr;
    831 #if K_OS == K_OS_OS2 || K_OS == K_OS_WINDOWS
     857#if K_OS == K_OS_DARWIN \
     858 || K_OS == K_OS_OS2 \
     859 || K_OS == K_OS_WINDOWS
    832860    return (KIPTR)pRdrFile->File;
    833861#else
     
    847875    if (pRdrFile->off == -1)
    848876    {
    849 #if K_OS == K_OS_OS2
     877#if K_OS == K_OS_DARWIN
     878
     879        pRdrFile->off = kHlpSys_lseek(pRdrFile->File, SEEK_CUR, 0);
     880        if (pRdrFile->off < 0)
     881            pRdrFile->off = -1;
     882
     883#elif K_OS == K_OS_OS2
    850884        ULONG ulNew;
    851885        APIRET rc = DosSetFilePtr(pRdrFile->File, 0, FILE_CURRENT, &ulNew);
     
    889923    /* check for underflow */
    890924    if (pRdrFile->cMappings <= 0)
    891 #if K_OS == K_OS_OS2 || K_OS == K_OS_WINDOWS
    892         return ERROR_INVALID_PARAMETER;
    893 #else
    894 # error "port me"
    895 #endif
     925        return KERR_INVALID_PARAMETER;
    896926
    897927    /* decrement usage counter, free mapping if no longer in use. */
     
    920950        KSIZE cb = (KSIZE)cbFile;
    921951        if (cb != cbFile)
    922             return ERROR_NOT_ENOUGH_MEMORY;
     952            return KERR_NO_MEMORY;
    923953
    924954        pRdrFile->pvMapping = kHlpAlloc(cb);
    925955        if (!pRdrFile->pvMapping)
    926 #if K_OS == K_OS_OS2 || K_OS == K_OS_WINDOWS
    927             return ERROR_NOT_ENOUGH_MEMORY;
    928 #else
    929 # error "port me"
    930 #endif
     956            return KERR_NO_MEMORY;
    931957        rc = pRdrFile->Core.pOps->pfnRead(pRdr, pRdrFile->pvMapping, cb, 0);
    932958        if (rc)
     
    955981    if (pRdrFile->off != off)
    956982    {
    957 #if K_OS == K_OS_OS2
     983#if K_OS == K_OS_DARWIN
     984        pRdrFile->off = kHlpSys_lseek(pRdrFile->File, SEEK_SET, off);
     985        if (pRdrFile->off < 0)
     986        {
     987            int rc = (int)-pRdrFile->off;
     988            pRdrFile->off = -1;
     989            return -rc;
     990        }
     991
     992#elif K_OS == K_OS_OS2
    958993        ULONG ulNew;
    959994        APIRET rc;
     
    9771012            int rc = GetLastError();
    9781013            if (!rc)
    979                 rc = ERROR_GEN_FAILURE;
     1014                rc = KERR_GENERAL_FAILURE;
    9801015            pRdrFile->off = -1;
    9811016            return rc;
     
    9901025     * Do the read.
    9911026     */
    992 #if K_OS == K_OS_OS2
     1027#if K_OS == K_OS_DARWIN
     1028    {
     1029    KSSIZE cbRead;
     1030
     1031    cbRead = kHlpSys_read(pRdrFile->File, pvBuf, cb);
     1032    if (cbRead != cb)
     1033    {
     1034        pRdrFile->off = -1;
     1035        if (cbRead < 0)
     1036            return -cbRead;
     1037        return KERR_GENERAL_FAILURE;
     1038    }
     1039    }
     1040
     1041#elif K_OS == K_OS_OS2
    9931042    {
    9941043    ULONG cbRead = 0;
     
    10021051    {
    10031052        pRdrFile->off = -1;
    1004         return ERROR_GEN_FAILURE;
     1053        return KERR_GENERAL_FAILURE;
    10051054    }
    10061055    }
     
    10131062        int rc = GetLastError();
    10141063        if (!rc)
    1015             rc = ERROR_GEN_FAILURE;
     1064            rc = KERR_GENERAL_FAILURE;
    10161065        pRdrFile->off = -1;
    10171066        return rc;
     
    10201069    {
    10211070        pRdrFile->off = -1;
    1022         return ERROR_GEN_FAILURE;
     1071        return KERR_GENERAL_FAILURE;
    10231072    }
    10241073    }
     
    10371086{
    10381087    PKRDRFILE    pRdrFile = (PKRDRFILE)pRdr;
    1039     int             rc;
    1040 #if K_OS == K_OS_OS2
     1088    int          rc;
     1089
     1090#if K_OS == K_OS_DARWIN
     1091    rc = kHlpSys_close(pRdrFile->File);
     1092
     1093#elif K_OS == K_OS_OS2
    10411094    rc = DosClose(pRdrFile->File);
    10421095
     
    10681121
    10691122    /*
    1070      * Open the file and determin its size.
    1071      */
    1072 #if K_OS == K_OS_OS2
    1073     ULONG           ulAction = 0;
    1074     FILESTATUS3     Info;
    1075     APIRET          rc;
    1076     HFILE           File = 0;
    1077     KFOFF           cb;
    1078     char            szFilename[CCHMAXPATH];
     1123     * Open the file, determin its size and correct filename.
     1124     */
     1125#if K_OS == K_OS_DARWIN
     1126    int         File;
     1127    KFOFF       cb;
     1128    KFOFF       rc;
     1129    char        szFilename[1024];
     1130
     1131    cchFilename = kHlpStrLen(pszFilename);
     1132    if (cchFilename >= sizeof(szFilename))
     1133        return KERR_OUT_OF_RANGE;
     1134    kHlpMemCopy(szFilename, pszFilename, cchFilename + 1);
     1135    /** @todo normalize the filename. */
     1136
     1137# ifdef O_BINARY
     1138    File = kHlpSys_open(pszFilename, O_RDONLY | O_BINARY, 0);
     1139# else
     1140    File = kHlpSys_open(pszFilename, O_RDONLY, 0);
     1141# endif
     1142    if (File < 0)
     1143        return -File;
     1144
     1145    cb = kHlpSys_lseek(File, SEEK_END, 0);
     1146    rc = kHlpSys_lseek(File, SEEK_SET, 0);
     1147    if (    cb < 0
     1148        ||  rc < 0)
     1149    {
     1150        kHlpSys_close(File);
     1151        return cb < 0 ? -cb : -rc;
     1152    }
     1153
     1154#elif K_OS == K_OS_OS2
     1155    ULONG       ulAction = 0;
     1156    FILESTATUS3 Info;
     1157    APIRET      rc;
     1158    HFILE       File = 0;
     1159    KFOFF       cb;
     1160    char        szFilename[CCHMAXPATH];
    10791161
    10801162    if ((uintptr_t)pszFilename >= 0x20000000)
     
    11521234    pRdrFile = (PKRDRFILE)kHlpAlloc(sizeof(*pRdrFile) + cchFilename);
    11531235    if (!pRdrFile)
    1154 #if K_OS == K_OS_OS2
    1155     {
     1236    {
     1237#if K_OS == K_OS_DARWIN
     1238        kHlpSys_close(File);
     1239#elif K_OS == K_OS_OS2
    11561240        DosClose(File);
    1157         return ERROR_NOT_ENOUGH_MEMORY;
    1158     }
    11591241#elif K_OS == K_OS_WINDOWS
    1160     {
    11611242        CloseHandle(File);
    1162         return ERROR_NOT_ENOUGH_MEMORY;
    1163     }
    11641243#else
    11651244# error "port me"
    11661245#endif
     1246        return KERR_NO_MEMORY;
     1247    }
    11671248
    11681249    /*
Note: See TracChangeset for help on using the changeset viewer.