Exemplo n.º 1
0
int
AsPutFile (
    char                    *Pathname,
    char                    *FileBuffer,
    UINT32                  SystemFlags)
{
    FILE                    *File;
    UINT32                  FileSize;
    size_t                  Actual;
    int                     Status = 0;


    /* Create the target file */

    if (!(SystemFlags & FLG_NO_CARRIAGE_RETURNS))
    {
        /* Put back the CR before each LF */

        AsInsertCarriageReturns (FileBuffer);
    }

    File = fopen (Pathname, "w+b");
    if (!File)
    {
        perror ("Could not create destination file");
        printf ("Could not create destination file \"%s\"\n", Pathname);
        return (-1);
    }

    /* Write the buffer to the file */

    FileSize = strlen (FileBuffer);
    Actual = fwrite (FileBuffer, 1, FileSize, File);
    if (Actual != FileSize)
    {
        printf ("Error writing output file \"%s\"\n", Pathname);
        Status = -1;
    }

    fclose (File);
    return (Status);
}
Exemplo n.º 2
0
int
AsPutFile (
    char                    *Pathname,
    char                    *FileBuffer,
    UINT32                  SystemFlags)
{
    UINT32                  FileSize;
    int                     DestHandle;
    int                     OpenFlags;


    /* Create the target file */

    OpenFlags = O_TRUNC | O_CREAT | O_WRONLY | O_BINARY;

    if (!(SystemFlags & FLG_NO_CARRIAGE_RETURNS))
    {
        /* Put back the CR before each LF */

        AsInsertCarriageReturns (FileBuffer);
    }

    DestHandle = open (Pathname, OpenFlags, S_IREAD | S_IWRITE);
    if (DestHandle == -1)
    {
        perror ("Could not create destination file");
        printf ("Could not create destination file \"%s\"\n", Pathname);
        return -1;
    }

    /* Write the buffer to the file */

    FileSize = strlen (FileBuffer);
    write (DestHandle, FileBuffer, FileSize);

    close (DestHandle);

    return 0;
}