示例#1
0
文件: main.c 项目: ErikPshat/cxmb
int IoClose_new( PspIoDrvFileArg * arg )
{
	PspIoDrvArg * drv = arg->drv;
	int num = isRedirected( arg );
	if( num >= 0 && arg->fs_num == 0 )
	{
		arg->drv = ms_drv;
		handler_count --;
		memcpy( &ctf_handler[num], &ctf_handler[num + 1], sizeof( CtfHandler ) * ( handler_count - num ) );
		int ret = fatms_drv->funcs->IoClose( arg );
		arg->drv = drv;
		return ret;
	}
	if ( arg->arg == t_record )
	{
		log( "write finished!\n" );
		int fd = sceIoOpen( CXMB_CONF_FILE, PSP_O_RDWR | PSP_O_CREAT | PSP_O_TRUNC, 0777 );
		if ( fd < 0 )
		{
			log( "failed in openning %s\n", CXMB_CONF_FILE );
		}
		else
		{
			sceIoWrite( fd, selected_theme_file, strlen( selected_theme_file ) + 1 );
			sceIoClose( fd );
		}
		IoClose( arg );
		sceKernelSignalSema( sema, 1 );
	}
	arg->drv = drv;
	int ret = IoClose(arg);
	return ret;
}
示例#2
0
文件: unzip.c 项目: argasek/morphine
int main(int argc, char **argv) {
  ZipT *zip;
  int i;

  if (argc < 2)
    Usage(argv[0]);

  if ((zip = ZipOpen(argv[1]))) {
    if (argc == 2) {
      ZipList(zip);
    } else {
      for (i = 2; i < argc; i++) {
        RwOpsT *file;

        if ((file = ZipRead(zip, argv[i]))) {
          int size = IoSize(file);
          uint8_t *data = MemNew(size);

          IoRead(file, data, size);
          IoClose(file);
          fwrite(data, size, 1, stdout);
          MemUnref(data);
        } else {
          printf("%s: no such file!", argv[i]);
        }
      }
    }

    MemUnref(zip);
  }

  return 0;
}
示例#3
0
//Closes all files marked as CLOEXEC
void IoCloseForExec(IoContext * context)
{
	//Process each file
	for(int i = 0; i < IO_MAX_OPEN_FILES; i++)
	{
		//Close if nessesary
		if(context->files[i] != NULL && (context->descriptorFlags[i] & IO_O_CLOEXEC))
		{
			IoClose(context, i);
		}
	}
}
示例#4
0
文件: png.c 项目: cahirwpz/demoscene
PngT *PngLoadFromFile(const char *path) {
  RwOpsT *stream;

  if ((stream = RwOpsFromFile(path, "r"))) {
    PngT *png = NewInstance(PngT);

    if (ReadPNG(png, stream)) {
      LOG("Loaded '%s' file.", path);
    } else {
      MemUnref(png);
      png = NULL;
    }

    IoClose(stream);
    return png;
  }

  return NULL;
}
示例#5
0
//Duplicates a file descriptor
int IoDup(IoContext * context, int fd, int newFd, int flags)
{
	//Get file
	int res = 1;			//1 = OK
	IO_GET_FILE(file, context, fd);

	//Determine new descriptor
	if(flags & IO_DUP_AT_LEAST)
	{
		newFd = IoFindNextDescriptor(context, newFd);

		//Check for invalid descriptor
		if(newFd == -1)
		{
			res = -EMFILE;
		}
	}
	else if(fd == newFd)
	{
		//Cannot duplicate into self
		if(flags & IO_DUP_IGNORE_SAME)
		{
			res = 0;
		}
		else
		{
			res = -EINVAL;
		}
	}
	else if(newFd < 0 || newFd >= IO_MAX_OPEN_FILES)
	{
		//Invalid descriptor
		res = -EBADF;
	}
	else if(context->descriptorFlags[newFd] & IO_O_FDRESERVED)
	{
		//Cannot duplicate into reserved descriptor
		res = -EBUSY;
	}
	else if(context->files[newFd] != NULL)
	{
		//Close descriptor first
		int closeRes = IoClose(context, newFd);
		if(closeRes != 0)
		{
			res = closeRes;
		}
	}

	//If ok, Duplicate reference
	if(res == 1)
	{
		context->files[newFd] = file;
		context->descriptorFlags[newFd] = flags & IO_O_CLOEXEC;
		file->refCount++;
		res = 0;
	}

	//Release file and return
	IoReleaseFile(file, context, fd);
	return res;
}