ULONG CurMaxFH = 0; LONG ReqCount = 1;
_PR_MD_OPEN(const char *name, PRIntn osflags, int mode){    HFILE file;    PRInt32 access = OPEN_SHARE_DENYNONE;    PRInt32 flags = 0L;    APIRET rc = 0;    PRUword actionTaken;    ULONG CurMaxFH = 0;    LONG ReqCount = 1;    ULONG fattr;    if (osflags & PR_SYNC) access |= OPEN_FLAGS_WRITE_THROUGH;    if (osflags & PR_RDONLY)        access |= OPEN_ACCESS_READONLY;    else if (osflags & PR_WRONLY)        access |= OPEN_ACCESS_WRITEONLY;    else if(osflags & PR_RDWR)        access |= OPEN_ACCESS_READWRITE;    if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL )    {        flags = OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_FAIL_IF_EXISTS;    }    else if (osflags & PR_CREATE_FILE)    {        if (osflags & PR_TRUNCATE)            flags = OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_REPLACE_IF_EXISTS;        else            flags = OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS;    }     else    {        if (osflags & PR_TRUNCATE)            flags = OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_REPLACE_IF_EXISTS;        else            flags = OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS;    }    if (isxdigit(mode) == 0) /* file attribs are hex, UNIX modes octal */        fattr = ((ULONG)mode == FILE_HIDDEN) ? FILE_HIDDEN : FILE_NORMAL;    else fattr = FILE_NORMAL;    do {        rc = DosOpen((char*)name,                     &file,            /* file handle if successful */                     &actionTaken,     /* reason for failure        */                     0,                /* initial size of new file  */                     fattr,            /* file system attributes    */                     flags,            /* Open flags                */                     access,           /* Open mode and rights      */                     0);               /* OS/2 Extended Attributes  */        if (rc == ERROR_TOO_MANY_OPEN_FILES) {            ULONG CurMaxFH = 0;            LONG ReqCount = 20;            APIRET rc2;            rc2 = DosSetRelMaxFH(&ReqCount, &CurMaxFH);            if (rc2 != NO_ERROR) {                break;            }        }    } while (rc == ERROR_TOO_MANY_OPEN_FILES);    if (rc != NO_ERROR) {        _PR_MD_MAP_OPEN_ERROR(rc);        return -1;     }    return (PRInt32)file;}