Example #1
0
void device_pty_interface::close(void)
{
	if (m_opened) {
		osd_close(m_pty_master);
		m_opened = false;
	}
}
Example #2
0
const void *core_fbuffer(core_file *file)
{
	file_error filerr;
	UINT32 read_length;

	/* if we already have data, just return it */
	if (file->data != NULL)
		return file->data;

	/* allocate some memory */
	file->data = (UINT8 *)malloc(file->length);
	if (file->data == NULL)
		return NULL;
	file->data_allocated = TRUE;

	/* read the file */
	filerr = osd_or_zlib_read(file, file->data, 0, file->length, &read_length);
	if (filerr != FILERR_NONE || read_length != file->length)
	{
		free(file->data);
		file->data = NULL;
		return NULL;
	}

	/* close the file because we don't need it anymore */
	osd_close(file->file);
	file->file = NULL;
	return file->data;
}
Example #3
0
static UINT64 get_file_size(const char *filename)
{
    osd_file *file;
    UINT64 filesize = 0;
    file_error filerr;

    filerr = osd_open(filename, OPEN_FLAG_READ, &file, &filesize);
    if (filerr == FILERR_NONE)
        osd_close(file);
    return filesize;
}
Example #4
0
void core_fclose(core_file *file)
{
	/* close files and free memory */
	if (file->zdata != NULL)
		core_fcompress(file, FCOMPRESS_NONE);
	if (file->file != NULL)
		osd_close(file->file);
	if (file->data != NULL && file->data_allocated)
		free(file->data);
	free(file);
}
Example #5
0
file_error osd_openpty(osd_file **file, char *name, size_t name_len)
{
        file_error res;
        UINT64 filesize;

        if ((res = osd_open(sdlfile_ptty_identifier , 0 , file , &filesize)) != FILERR_NONE) {
                return res;
        }

        if ((res = sdl_slave_name_ptty(*file , name , name_len)) != FILERR_NONE) {
                osd_close(*file);
        }

        return res;
}
Example #6
0
static void free_zip_file(zip_file *zip)
{
	if (zip != nullptr)
	{
		if (zip->file != nullptr)
			osd_close(zip->file);
		if (zip->filename != nullptr)
			free((void *)zip->filename);
		if (zip->ecd.raw != nullptr)
			free(zip->ecd.raw);
		if (zip->cd != nullptr)
			free(zip->cd);
		free(zip);
	}
}
Example #7
0
static void free__7z_file(_7z_file *_7z)
{
	if (_7z != NULL)
	{
		if (_7z->archiveStream.file._7z_osdfile != NULL)
			osd_close(_7z->archiveStream.file._7z_osdfile);
		if (_7z->filename != NULL)
			free((void *)_7z->filename);


		if (_7z->outBuffer) IAlloc_Free(&_7z->allocImp, _7z->outBuffer);
		if (_7z->inited) SzArEx_Free(&_7z->db, &_7z->allocImp);


		free(_7z);
	}
}
Example #8
0
void _7z_file_close(_7z_file *_7z)
{
	int cachenum;

	/* close the open files */
	if (_7z->archiveStream.file._7z_osdfile != NULL)
		osd_close(_7z->archiveStream.file._7z_osdfile);
	_7z->archiveStream.file._7z_osdfile = NULL;

	/* find the first NULL entry in the cache */
	for (cachenum = 0; cachenum < ARRAY_LENGTH(_7z_cache); cachenum++)
		if (_7z_cache[cachenum] == NULL)
			break;

	/* if no room left in the cache, free the bottommost entry */
	if (cachenum == ARRAY_LENGTH(_7z_cache))
		free__7z_file(_7z_cache[--cachenum]);

	/* move everyone else down and place us at the top */
	if (cachenum != 0)
		memmove(&_7z_cache[1], &_7z_cache[0], cachenum * sizeof(_7z_cache[0]));
	_7z_cache[0] = _7z;
}
int main()
{
	int ret = 0;
	const char *root = "/tmp/osd/";
	struct osd_device osd;

	system("rm -rf /tmp/osd");
	ret = osd_open(root, &osd);
	assert(ret == 0);
	
	test_set_one_attr(&osd); 
	/* test_partition(&osd); */
	/* test_create(&osd); */
	/* test_query(&osd); */
	/* test_list(&osd); */
	/* test_set_member_attributes(&osd); */
	/* test_atomics(&osd); */

	ret = osd_close(&osd);
	assert(ret == 0);

	return 0;
}
Example #10
0
void zip_file_close(zip_file *zip)
{
	int cachenum;

	/* close the open files */
	if (zip->file != nullptr)
		osd_close(zip->file);
	zip->file = nullptr;

	/* find the first NULL entry in the cache */
	for (cachenum = 0; cachenum < ARRAY_LENGTH(zip_cache); cachenum++)
		if (zip_cache[cachenum] == nullptr)
			break;

	/* if no room left in the cache, free the bottommost entry */
	if (cachenum == ARRAY_LENGTH(zip_cache))
		free_zip_file(zip_cache[--cachenum]);

	/* move everyone else down and place us at the top */
	if (cachenum != 0)
		memmove(&zip_cache[1], &zip_cache[0], cachenum * sizeof(zip_cache[0]));
	zip_cache[0] = zip;
}
Example #11
0
static void identify_file(const char *name, romident_status *status)
{
	file_error filerr;
	osd_file *file;
	UINT64 length;

	/* open for read and process if it opens and has a valid length */
	filerr = osd_open(name, OPEN_FLAG_READ, &file, &length);
	if (filerr == FILERR_NONE && length > 0 && (UINT32)length == length)
	{
		UINT8 *data = (UINT8 *)malloc(length);
		if (data != NULL)
		{
			UINT32 bytes;

			/* read file data into RAM and identify it */
			filerr = osd_read(file, data, 0, length, &bytes);
			if (filerr == FILERR_NONE)
				identify_data(name, data, bytes, status);
			free(data);
		}
		osd_close(file);
	}
}
Example #12
0
static void image_clear(mess_image *image)
{
	if (image->file)
	{
		osd_close(image->file);
		image->file = NULL;
	}

	pool_exit(&image->mempool);
	image->writeable = 0;
	image->created = 0;
	image->name = NULL;
	image->dir = NULL;
	image->hash = NULL;
	image->length = 0;
	image->pos = 0;
	image->longname = NULL;
	image->manufacturer = NULL;
	image->year = NULL;
	image->playable = NULL;
	image->extrainfo = NULL;
	image->basename_noext = NULL;
	image->ptr = NULL;
}
Example #13
0
int main(int argc, char **argv)
{
	int numiter = 100;
	int numobj = 200;
	int numobj_in_coll = 100;
	int nummatch = 20;
	int numattr = 10;
	int numcriteria = 3;
	static struct osd_device osd;
	int ret;

	osd_set_progname(argc, argv);
	while (++argv, --argc > 0) {
		const char *s = *argv;
		if (s[0] == '-') {
			switch (s[1]) {
			case 'i':
				++argv, --argc;
				if (argc < 1)
					usage();
				numiter = atoi(*argv);
				break;
			case 'o':
				++argv, --argc;
				if (argc < 1)
					usage();
				numobj = atoi(*argv);
				break;
			case 'c':
				++argv, --argc;
				if (argc < 1)
					usage();
				numobj_in_coll = atoi(*argv);
				break;
			case 'm':
				++argv, --argc;
				if (argc < 1)
					usage();
				nummatch = atoi(*argv);
				break;
			case 'a':
				++argv, --argc;
				if (argc < 1)
					usage();
				numattr = atoi(*argv);
				break;
			case 'n':
				++argv, --argc;
				if (argc < 1)
					usage();
				numcriteria = atoi(*argv);
				break;
			default:
				usage();
			}
		} else
			usage();
	}

	system("rm -rf /tmp/osd");
	ret = osd_open("/tmp/osd", &osd);
	assert(ret == 0);

	query_speed(&osd, numiter, numobj, numobj_in_coll, nummatch,
		    numattr, numcriteria);

	ret = osd_close(&osd);
	assert(ret == 0);

	return 0;
}
int main(int argc, char **argv)
{
	int ret = 0;
	int numobj = 10;
	int numiter = 10;
	int numattr = 10;
	int numpg = 10;
	const char *root = "/tmp/osd/";
	const char *func = NULL;
	struct osd_device osd;

	osd_set_progname(argc, argv);
	while (++argv, --argc > 0) {
		const char *s = *argv;
		if (s[0] == '-') {
			switch (s[1]) {
			case 'i':
				++argv, --argc;
				if (argc < 1)
					usage();
				numiter = atoi(*argv);
				break;
			case 'o':
				++argv, --argc;
				if (argc < 1)
					usage();
				numobj = atoi(*argv);
				break;
			case 'a':
				++argv, --argc;
				if (argc < 1)
					usage();
				numattr = atoi(*argv);
				break;
			case 'p':
				++argv, --argc;
				if (argc < 1)
					usage();
				numpg = atoi(*argv);
				break;
			case 't':
				++argv, --argc;
				if (argc < 1)
					usage();
				func = *argv;
				break;
			default:
				usage();
			}
		}
	}

	if (!func)
		usage();

	system("rm -rf /tmp/osd/*");
	ret = osd_open(root, &osd);
	assert(ret == 0);

  	if (!strcmp(func, "collinsert")) {
		time_coll_insert(&osd, numobj, numiter, 0);
	} else if (!strcmp(func, "collinsertone")) {
		time_coll_insert(&osd, numobj, numiter, 1);
	} else if (!strcmp(func, "colldelete")) {
		time_coll_delete(&osd, numobj, numiter, 0);
	} else if (!strcmp(func, "colldeleteone")) {
		time_coll_delete(&osd, numobj, numiter, 1);
	} else if (!strcmp(func, "objinsert")) {
		time_obj_insert(&osd, numobj, numiter, 0);
	} else if (!strcmp(func, "objinsertone")) {
		time_obj_insert(&osd, numobj, numiter, 1);
	} else if (!strcmp(func, "objdelete")) {
		time_obj_delete(&osd, numobj, numiter, 0);
	} else if (!strcmp(func, "objdeleteone")) {
		time_obj_delete(&osd, numobj, numiter, 1);
	} else if (!strcmp(func, "objdelpid")) {
		time_obj_delpid(&osd, numobj, numiter);
	} else if (!strcmp(func, "objnextpid")) {
		time_obj_generic(&osd, numobj, numiter, 1);
	} else if (!strcmp(func, "objnextoid")) {
		time_obj_generic(&osd, numobj, numiter, 2);
	} else if (!strcmp(func, "objpresent")) {
		time_obj_generic(&osd, numobj, numiter, 3);
	} else if (!strcmp(func, "objnotpresent")) {
		time_obj_generic(&osd, numobj, numiter, 4);
	} else if (!strcmp(func, "objpidempty")) {
		time_obj_generic(&osd, numobj, numiter, 5);
	} else if (!strcmp(func, "objgettype")) {
		time_obj_generic(&osd, numobj, numiter, 6);
	} else if (!strcmp(func, "objgetoids")) {
		time_obj_fetch(&osd, numobj, numiter, 1);
	} else if (!strcmp(func, "objgetcids")) {
		time_obj_fetch(&osd, numobj, numiter, 2);
	} else if (!strcmp(func, "objgetpids")) {
		time_obj_fetch(&osd, numobj, numiter, 3);
	} else if (!strcmp(func, "objgetfullpids")) {
		time_obj_fetch(&osd, numobj, numiter, 4);
	} else if (!strcmp(func, "attrsetone")) {
		time_attr(&osd, numpg, numattr, numiter, 1, func);
	} else if (!strcmp(func, "attrgetone")) {
		time_attr(&osd, numpg, numattr, numiter, 2, func);
	} else if (!strcmp(func, "attrdelone")) {
		time_attr(&osd, numpg, numattr, numiter, 3, func);
	} else if (!strcmp(func, "attrset")) {
		time_attr(&osd, numpg, numattr, numiter, 4, func);
	} else if (!strcmp(func, "attrget")) {
		time_attr(&osd, numpg, numattr, numiter, 5, func);
	} else if (!strcmp(func, "attrdel")) {
		time_attr(&osd, numpg, numattr, numiter, 6, func);
	} else if (!strcmp(func, "attrdirpg")) {
		time_attr(&osd, numpg, numattr, numiter, 7, func);
	} else if (!strcmp(func, "attrforallpg")) {
		time_attr(&osd, numpg, numattr, numiter, 8, func);
	} else if (!strcmp(func, "attrpgaslst")) {
		time_attr(&osd, numpg, numattr, numiter, 9, func);
	} else {
		usage();
	} 

	ret = osd_close(&osd);
	assert(ret == 0);

	return 0;
}
Example #15
0
/*-------------------------------------------------
    parse_wav_sample - takes a .WAV file, verifies
    that the file is 16 bits, and returns the
    length in bytes of the data and the offset in
    bytes to where the data starts in the file.
-------------------------------------------------*/
static UINT32 parse_wav_sample(const char *filename, UINT32 *dataoffs)
{
	unsigned long offset = 0;
	UINT32 length, rate, filesize;
	UINT16 bits, temp16;
	char buf[32];
	osd_file *file;
	file_error filerr;
	UINT64 fsize = 0;
	UINT32 actual;

	filerr = osd_open(filename, OPEN_FLAG_READ, &file, &fsize);
	if (filerr != FILERR_NONE)
	{
		printf("ERROR: could not open (%s)\n", filename);
		return 0;
	}

	/* read the core header and make sure it's a WAVE file */
	osd_read(file, buf, 0, 4, &actual);
	offset += actual;
	if (offset < 4)
	{
		osd_close(file);
		printf("ERROR: unexpected RIFF offset %lu (%s)\n", offset, filename);
		return 0;
	}
	if (memcmp(&buf[0], "RIFF", 4) != 0)
	{
		osd_close(file);
		printf("ERROR: could not find RIFF header (%s)\n", filename);
		return 0;
	}

	/* get the total size */
	osd_read(file, &filesize, offset, 4, &actual);
	offset += actual;
	if (offset < 8)
	{
		osd_close(file);
		printf("ERROR: unexpected size offset %lu (%s)\n", offset, filename);
		return 0;
	}
	filesize = LITTLE_ENDIANIZE_INT32(filesize);

	/* read the RIFF file type and make sure it's a WAVE file */
	osd_read(file, buf, offset, 4, &actual);
	offset += actual;
	if (offset < 12)
	{
		osd_close(file);
		printf("ERROR: unexpected WAVE offset %lu (%s)\n", offset, filename);
		return 0;
	}
	if (memcmp(&buf[0], "WAVE", 4) != 0)
	{
		osd_close(file);
		printf("ERROR: could not find WAVE header (%s)\n", filename);
		return 0;
	}

	/* seek until we find a format tag */
	while (1)
	{
		osd_read(file, buf, offset, 4, &actual);
		offset += actual;
		osd_read(file, &length, offset, 4, &actual);
		offset += actual;
		length = LITTLE_ENDIANIZE_INT32(length);
		if (memcmp(&buf[0], "fmt ", 4) == 0)
			break;

		/* seek to the next block */
		offset += length;
		if (offset >= filesize)
		{
			osd_close(file);
			printf("ERROR: could not find fmt tag (%s)\n", filename);
			return 0;
		}
	}

	/* read the format -- make sure it is PCM */
	osd_read(file, &temp16, offset, 2, &actual);
	offset += actual;
	temp16 = LITTLE_ENDIANIZE_INT16(temp16);
	if (temp16 != 1)
	{
		osd_close(file);
		printf("ERROR: unsupported format %u - only PCM is supported (%s)\n", temp16, filename);
		return 0;
	}

	/* number of channels -- only stereo is supported */
	osd_read(file, &temp16, offset, 2, &actual);
	offset += actual;
	temp16 = LITTLE_ENDIANIZE_INT16(temp16);
	if (temp16 != 2)
	{
		osd_close(file);
		printf("ERROR: unsupported number of channels %u - only stereo is supported (%s)\n", temp16, filename);
		return 0;
	}

	/* sample rate */
	osd_read(file, &rate, offset, 4, &actual);
	offset += actual;
	rate = LITTLE_ENDIANIZE_INT32(rate);
	if (rate != 44100)
	{
		osd_close(file);
		printf("ERROR: unsupported samplerate %u - only 44100 is supported (%s)\n", rate, filename);
		return 0;
	}

	/* bytes/second and block alignment are ignored */
	osd_read(file, buf, offset, 6, &actual);
	offset += actual;

	/* bits/sample */
	osd_read(file, &bits, offset, 2, &actual);
	offset += actual;
	if (bits != 16)
	{
		osd_close(file);
		printf("ERROR: unsupported bits/sample %u - only 16 is supported (%s)\n", bits, filename);
		return 0;
	}

	/* seek past any extra data */
	offset += length - 16;

	/* seek until we find a data tag */
	while (1)
	{
		osd_read(file, buf, offset, 4, &actual);
		offset += actual;
		osd_read(file, &length, offset, 4, &actual);
		offset += actual;
		length = LITTLE_ENDIANIZE_INT32(length);
		if (memcmp(&buf[0], "data", 4) == 0)
			break;

		/* seek to the next block */
		offset += length;
		if (offset >= filesize)
		{
			osd_close(file);
			printf("ERROR: could not find data tag (%s)\n", filename);
			return 0;
		}
	}

	osd_close(file);

	/* if there was a 0 length data block, we're done */
	if (length == 0)
	{
		printf("ERROR: empty data block (%s)\n", filename);
		return 0;
	}

	*dataoffs = offset;

	return length;
}
Example #16
0
static void identify_file(core_options *options, const char *name, romident_status *status)
{
	file_error filerr;
	osd_file *file;
	UINT64 length;

	if (core_filename_ends_with(name, ".chd"))
	{
		chd_file *chd;
		chd_error err;
		astring basename;
		int found = 0;

		core_filename_extract_base(&basename, name, FALSE);
		mame_printf_info("%-20s", basename.cstr());

		status->total++;

		err = chd_open(name, CHD_OPEN_READ, NULL, &chd);
		if (err != CHDERR_NONE)
		{
			mame_printf_info("NOT A CHD\n");
			status->nonroms++;
		}
		else
		{
			chd_header header;

			header = *chd_get_header(chd);
			if (header.flags & CHDFLAGS_IS_WRITEABLE)
			{
				mame_printf_info("is a writable CHD\n");
			}
			else
			{
				static const UINT8 nullhash[HASH_BUF_SIZE] = { 0 };
				char			hash[HASH_BUF_SIZE];	/* actual hash information */

				hash_data_clear(hash);

				/* if there's an MD5 or SHA1 hash, add them to the output hash */
				if (memcmp(nullhash, header.md5, sizeof(header.md5)) != 0)
					hash_data_insert_binary_checksum(hash, HASH_MD5, header.md5);
				if (memcmp(nullhash, header.sha1, sizeof(header.sha1)) != 0)
					hash_data_insert_binary_checksum(hash, HASH_SHA1, header.sha1);

				length = header.logicalbytes;

				match_roms(options, hash, length, &found);

				if (found == 0)
				{
					mame_printf_info("NO MATCH\n");
				}

				/* if we did find it, count it as a match */
				else
					status->matches++;
			}

			chd_close(chd);
		}
	}
	else
	{
		/* open for read and process if it opens and has a valid length */
		filerr = osd_open(name, OPEN_FLAG_READ, &file, &length);
		if (filerr == FILERR_NONE && length > 0 && (UINT32)length == length)
		{
			UINT8 *data = global_alloc_array(UINT8, length);
			if (data != NULL)
			{
				UINT32 bytes;

				/* read file data into RAM and identify it */
				filerr = osd_read(file, data, 0, length, &bytes);
				if (filerr == FILERR_NONE)
					identify_data(options, name, data, bytes, status);
				global_free(data);
			}
			osd_close(file);
		}
	}
}