Logo Search packages:      
Sourcecode: virtualbox-ose version File versions  Download package

static int kPrfWriteFile ( const char *  pszName,
const void *  pvData,
KU32  cbData 
) [static]

Writes a data buffer to a new file.

Any existing file will be overwritten.

Returns:
0 on success.

-1 on failure.

Parameters:
pszName The name of the file.
pvData The data to write.
cbData The amount of data to write.

Definition at line 1367 of file kProfileR3.cpp.

References DWORD.

Referenced by kPrfTerminate().

{
#if K_OS == K_OS_WINDOWS
    int rc = -1;
    HANDLE hFile = CreateFile(pszName,GENERIC_WRITE, FILE_SHARE_READ, NULL,
                              CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, INVALID_HANDLE_VALUE);
    if (hFile != INVALID_HANDLE_VALUE)
    {
        DWORD dwWritten;
        if (    WriteFile(hFile, pvData, cbData, &dwWritten, NULL)
            &&  dwWritten == cbData)
            rc = 0;
        CloseHandle(hFile);
    }
    return rc;

#elif K_OS == K_OS_OS2
    HFILE hFile;
    ULONG ulAction = 0;
    APIRET rc = DosOpen(pszName, &hFile, &ulAction, cbData, FILE_NORMAL,
                        OPEN_ACTION_REPLACE_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW,
                        OPEN_ACCESS_WRITEONLY | OPEN_SHARE_DENYWRITE | OPEN_FLAGS_NOINHERIT | OPEN_FLAGS_SEQUENTIAL,
                        NULL);
    if (!rc)
    {
        ULONG cbWritten;
        rc = DosWrite(hFile, pvData, cbData, &cbWritten);
        if (!rc && cbWritten != cbData)
            rc = -1;
        DosClose(hFile);
    }
    return rc ? -1 : 0;

#else
    int rc = -1;
    int fd = open(pszName, O_WRONLY | O_CREAT | O_BINARY | O_TRUNC, 0666);
    if (fd >= 0)
    {
        if (write(fd, pvData, cbData) == cbData)
            rc = 0;
        close(fd);
    }
    return rc;

#endif
}


Generated by  Doxygen 1.6.0   Back to index