Esempio n. 1
0
bool File::flush()
{
	if (!file || (mode != WRITE && mode != APPEND))
		throw love::Exception("File is not opened for writing.");

	return PHYSFS_flush(file) != 0;
}
Esempio n. 2
0
File::~File()
{
	if (m_fileHandle)
	{
		if (m_mode&EFM_WRITE)
			PHYSFS_flush(m_fileHandle);

		PHYSFS_close(m_fileHandle);
	}
}
Esempio n. 3
0
bool NETlogEntry(const char *str,UDWORD a,UDWORD b)
{
    static const char star_line[] = "************************************************************\n";
    static UDWORD lastframe = 0;
    UDWORD frame= frameGetFrameNumber();
    time_t aclock;
    struct tm *newtime;
    char buf[256];

    if (!pFileHandle)
    {
        return false;
    }

    time( &aclock );					/* Get time in seconds */
    newtime = localtime( &aclock );		/* Convert time to struct */

    if (!newtime || !str || !pFileHandle)
    {
        debug(LOG_ERROR, "Fatal error averted in NETlog");
        return false;
    }

    // check to see if a new frame.
    if(frame != lastframe)
    {
        static const char dash_line[] = "-----------------------------------------------------------\n";

        lastframe = frame;
        PHYSFS_write(pFileHandle, dash_line, strlen(dash_line), 1);
    }

    if (a < NUM_GAME_PACKETS)
        // replace common msgs with txt descriptions
        snprintf(buf, sizeof(buf), "%s \t: %s \t:%d\t\t%s", str, messageTypeToString(a), b, asctime(newtime));
    else if (a == SYNC_FLAG)
        snprintf(buf, sizeof(buf), "%s \t: %d \t(Sync) \t%s", str, b, asctime(newtime));
    else
        snprintf(buf, sizeof(buf), "%s \t:%d \t\t\t:%d\t\t%s", str, a, b, asctime(newtime));

    if (a == NET_PLAYER_LEAVING || a == NET_PLAYER_DROPPED )
    {
        // Write a starry line above NET_LEAVING messages
        PHYSFS_write(pFileHandle, star_line, strlen(star_line), 1);
        PHYSFS_write(pFileHandle, buf, strlen( buf ), 1);
        PHYSFS_write(pFileHandle, star_line, strlen(star_line), 1);
    }
    else
    {
        PHYSFS_write(pFileHandle, buf, strlen( buf ), 1);
    }

    PHYSFS_flush(pFileHandle);
    return true;
}
static bool file_phys_fflush(ALLEGRO_FILE *f)
{
   ALLEGRO_FILE_PHYSFS *fp = cast_stream(f);

   if (!PHYSFS_flush(fp->phys)) {
      phys_set_errno(fp);
      return false;
   }

   return true;
}
Esempio n. 5
0
void FileStream::flush()
{
    if(!m_writeable)
        throwError("filestream is not writeable");

    if(m_fileHandle) {
        if(m_caching) {
            if(!PHYSFS_seek(m_fileHandle, 0))
                throwError("flush seek failed", true);
            uint len = m_data.size();
            if(PHYSFS_write(m_fileHandle, m_data.data(), 1, len) != len)
                throwError("flush write failed", true);
        }

        if(PHYSFS_flush(m_fileHandle) == 0)
            throwError("flush failed", true);
    }
}
Esempio n. 6
0
	void PhysFSLogFile::Flush()
	{
		if (m_Open)
		{
			PHYSFS_flush(m_File);
			if (m_CurrentLength > m_MaxLength)
			{
				PHYSFS_close(m_File);
				PHYSFS_File *reread = PHYSFS_openRead(m_Filename.c_str());

				PHYSFS_sint64 seekPosition = m_StartingLength;
				PHYSFS_uint64 keptLength = m_SessionLength;
				if (m_SessionLength > m_MaxLength)
				{
					seekPosition = m_StartingLength + m_ExtraSpace;
					keptLength = m_SessionLength - m_ExtraSpace;
				}

				PHYSFS_sint64 count = -1;
				std::string buffer("");
				if (PHYSFS_seek(reread, seekPosition) != 0)
				{
					buffer.resize((size_t)keptLength, '\0');
					count = PHYSFS_read(reread, static_cast<void*>(&buffer[0]), buffer.size(), 1);
				}

				PHYSFS_close(reread);

				m_File = PHYSFS_openWrite(m_Filename.c_str());

				//if (keptLength < m_SessionLength)
				//{
				//	static const char message[] = "***Log exceeded maximum size and was trimmed to this point***\n\0";
				//	static size_t messageLength = strlen(message);
				//	PHYSFS_write(m_File, &message, 1, messageLength);
				//}
				if (count != -1)
					PHYSFS_write(m_File, static_cast<const void*>(buffer.c_str()), 1, buffer.length());

				m_StartingLength = 0;
				m_CurrentLength = m_SessionLength = buffer.size();
			}
		}
	}
Esempio n. 7
0
int fs_flush(fs_file fh)
{
    return PHYSFS_flush(fh->handle);
}
Esempio n. 8
0
static int cmd_stressbuffer(char *args)
{
    int num;

    if (*args == '\"')
    {
        args++;
        args[strlen(args) - 1] = '\0';
    } /* if */

    num = atoi(args);
    if (num < 0)
        printf("buffer must be greater than or equal to zero.\n");
    else
    {
        PHYSFS_File *f;
        int rndnum;

        printf("Stress testing with (%d) byte buffer...\n", num);
        f = PHYSFS_openWrite("test.txt");
        if (f == NULL)
            printf("Couldn't open test.txt for writing: %s.\n", PHYSFS_getLastError());
        else
        {
            int i, j;
            char buf[37];
            char buf2[37];

            if (!PHYSFS_setBuffer(f, num))
            {
                printf("PHYSFS_setBuffer() failed: %s.\n", PHYSFS_getLastError());
                PHYSFS_close(f);
                PHYSFS_delete("test.txt");
                return(1);
            } /* if */

            strcpy(buf, "abcdefghijklmnopqrstuvwxyz0123456789");
            srand((unsigned int) time(NULL));

            for (i = 0; i < 10; i++)
            {
                for (j = 0; j < 10000; j++)
                {
                    PHYSFS_uint32 right = 1 + (PHYSFS_uint32) (35.0 * rand() / (RAND_MAX + 1.0));
                    PHYSFS_uint32 left = 36 - right;
                    if (PHYSFS_write(f, buf, left, 1) != 1)
                    {
                        printf("PHYSFS_write() failed: %s.\n", PHYSFS_getLastError());
                        PHYSFS_close(f);
                        return(1);
                    } /* if */

                    rndnum = 1 + (int) (1000.0 * rand() / (RAND_MAX + 1.0));
                    if (rndnum == 42)
                    {
                        if (!PHYSFS_flush(f))
                        {
                            printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
                            PHYSFS_close(f);
                            return(1);
                        } /* if */
                    } /* if */

                    if (PHYSFS_write(f, buf + left, 1, right) != right)
                    {
                        printf("PHYSFS_write() failed: %s.\n", PHYSFS_getLastError());
                        PHYSFS_close(f);
                        return(1);
                    } /* if */

                    rndnum = 1 + (int) (1000.0 * rand() / (RAND_MAX + 1.0));
                    if (rndnum == 42)
                    {
                        if (!PHYSFS_flush(f))
                        {
                            printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
                            PHYSFS_close(f);
                            return(1);
                        } /* if */
                    } /* if */
                } /* for */

                if (!PHYSFS_flush(f))
                {
                    printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
                    PHYSFS_close(f);
                    return(1);
                } /* if */

            } /* for */

            if (!PHYSFS_close(f))
            {
                printf("PHYSFS_close() failed: %s.\n", PHYSFS_getLastError());
                return(1);  /* oh well. */
            } /* if */

            printf(" ... test file written ...\n");
            f = PHYSFS_openRead("test.txt");
            if (f == NULL)
            {
                printf("Failed to reopen stress file for reading: %s.\n", PHYSFS_getLastError());
                return(1);
            } /* if */

            if (!PHYSFS_setBuffer(f, num))
            {
                printf("PHYSFS_setBuffer() failed: %s.\n", PHYSFS_getLastError());
                PHYSFS_close(f);
                return(1);
            } /* if */

            for (i = 0; i < 10; i++)
            {
                for (j = 0; j < 10000; j++)
                {
                    PHYSFS_uint32 right = 1 + (PHYSFS_uint32) (35.0 * rand() / (RAND_MAX + 1.0));
                    PHYSFS_uint32 left = 36 - right;
                    if (PHYSFS_read(f, buf2, left, 1) != 1)
                    {
                        printf("PHYSFS_read() failed: %s.\n", PHYSFS_getLastError());
                        PHYSFS_close(f);
                        return(1);
                    } /* if */

                    rndnum = 1 + (int) (1000.0 * rand() / (RAND_MAX + 1.0));
                    if (rndnum == 42)
                    {
                        if (!PHYSFS_flush(f))
                        {
                            printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
                            PHYSFS_close(f);
                            return(1);
                        } /* if */
                    } /* if */

                    if (PHYSFS_read(f, buf2 + left, 1, right) != right)
                    {
                        printf("PHYSFS_read() failed: %s.\n", PHYSFS_getLastError());
                        PHYSFS_close(f);
                        return(1);
                    } /* if */

                    rndnum = 1 + (int) (1000.0 * rand() / (RAND_MAX + 1.0));
                    if (rndnum == 42)
                    {
                        if (!PHYSFS_flush(f))
                        {
                            printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
                            PHYSFS_close(f);
                            return(1);
                        } /* if */
                    } /* if */

                    if (memcmp(buf, buf2, 36) != 0)
                    {
                        printf("readback is mismatched on iterations (%d, %d).\n", i, j);
                        printf("wanted: [");
                        for (i = 0; i < 36; i++)
                            printf("%c", buf[i]);
                        printf("]\n");

                        printf("   got: [");
                        for (i = 0; i < 36; i++)
                            printf("%c", buf2[i]);
                        printf("]\n");
                        PHYSFS_close(f);
                        return(1);
                    } /* if */
                } /* for */

                if (!PHYSFS_flush(f))
                {
                    printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
                    PHYSFS_close(f);
                    return(1);
                } /* if */

            } /* for */

            printf(" ... test file read ...\n");

            if (!PHYSFS_eof(f))
                printf("PHYSFS_eof() returned true! That's wrong.\n");

            if (!PHYSFS_close(f))
            {
                printf("PHYSFS_close() failed: %s.\n", PHYSFS_getLastError());
                return(1);  /* oh well. */
            } /* if */

            PHYSFS_delete("test.txt");
            printf("stress test completed successfully.\n");
        } /* else */
    } /* else */

    return(1);
} /* cmd_stressbuffer */
void File::flush()
{
    PHYSFS_flush(file); // no exception - what should an app do if flush fails?
}
Esempio n. 10
0
static void wzpng_flush_data(png_structp png_ptr)
{
	PHYSFS_file* fileHandle = (PHYSFS_file*)png_get_io_ptr(png_ptr);

	PHYSFS_flush(fileHandle);
}
Esempio n. 11
0
File: fsys.c Progetto: exdev/exsdk
int ex_fsys_fflush ( ex_file_t *_file ) {
    return PHYSFS_flush(_file);
}
 bool FileDevice::flush()
 {
   if (!PHYSFS_flush(file))
     throw Exception(PHYSFS_getLastError());
   return true;
 }