void neogeo_exit(void) { SceUID fd; char path[MAX_PATH]; msg_printf(TEXT(PLEASE_WAIT2)); sprintf(path, "%smemcard/%s.bin", launchDir, game_name); if ((fd = sceIoOpen(path, PSP_O_WRONLY|PSP_O_CREAT, 0777)) >= 0) { sceIoWrite(fd, neogeo_memcard, 0x800); sceIoClose(fd); } sprintf(path, "%snvram/%s.nv", launchDir, game_name); if ((fd = sceIoOpen(path, PSP_O_WRONLY|PSP_O_CREAT, 0777)) >= 0) { swab(neogeo_sram16, neogeo_sram16, 0x2000); sceIoWrite(fd, neogeo_sram16, 0x2000); sceIoClose(fd); } msg_printf(TEXT(DONE2)); sound_exit(); memory_shutdown(); }
/* Buffer up the data */ size_t write_callback(void *ptr, size_t size, size_t nmemb, void *data) { int *fd = (int *) data; int totalsize = size * nmemb; int ret = totalsize; if((totalsize + g_writebufpos) < WRITEBUF_SIZE) { memcpy(&g_writebuf[g_writebufpos], ptr, totalsize); g_writebufpos += totalsize; } else { if(g_writebufpos > 0) { sceIoWrite(*fd, g_writebuf, g_writebufpos); g_writebufpos = 0; } while(totalsize > WRITEBUF_SIZE) { sceIoWrite(*fd, ptr, WRITEBUF_SIZE); totalsize -= WRITEBUF_SIZE; ptr += WRITEBUF_SIZE; } if(totalsize > 0) { memcpy(g_writebuf, ptr, totalsize); g_writebufpos = totalsize; } } return ret; }
void __pspgl_vram_dump (void) { unsigned long vram_start = (unsigned long) sceGeEdramGetAddr(); unsigned long vram_size = (unsigned long) sceGeEdramGetSize() * 4; unsigned long header [4]; unsigned char vram_copy [0x10000]; int fd; int i; fd = sceIoOpen(PSPGL_GE_DUMPFILE, PSP_O_CREAT | PSP_O_APPEND | PSP_O_WRONLY, 0644); if (pspgl_curctx) { struct pspgl_surface *s = pspgl_curctx->draw; struct pspgl_dump_surfaces surf; header[0] = PSPGL_GE_DUMP_SURFACES; header[1] = sizeof(header) + sizeof(surf); header[2] = 0; header[3] = 0; memset(&surf, 0, sizeof(surf)); surf.pixfmt = s->pixfmt; surf.alpha_mask = s->alpha_mask; surf.stencil_mask = s->stencil_mask; surf.front.start = s->color_front->base - sceGeEdramGetAddr(); surf.front.size = s->height * s->pixelperline * (s->pixfmt == GE_RGBA_8888 ? 4 : 2); surf.front.stride = s->pixelperline; surf.back.start = s->color_back->base - sceGeEdramGetAddr(); surf.back.size = s->height * s->pixelperline * (s->pixfmt == GE_RGBA_8888 ? 4 : 2); surf.back.stride = s->pixelperline; if (s->depth_buffer) { surf.depth.start = s->depth_buffer->base - sceGeEdramGetAddr(); surf.depth.size = s->height * s->pixelperline * 2; surf.depth.stride = s->pixelperline; } sceIoWrite(fd, header, sizeof(header)); sceIoWrite(fd, &surf, sizeof(surf)); } header[0] = PSPGL_GE_DUMP_VRAM; header[1] = sizeof(header) + vram_size; header[2] = vram_start; header[3] = vram_size; sceIoWrite(fd, header, sizeof(header)); /* copy in blocks, direct writes from VRAM to file don't seem to work... */ for (i=0; i<vram_size/sizeof(vram_copy); i++, vram_start+=sizeof(vram_copy)) { memcpy(vram_copy, (void *) vram_start, sizeof(vram_copy)); sceIoWrite(fd, (void *) vram_copy, sizeof(vram_copy)); } sceIoClose(fd); }
int colorconfig_write(ColorConfig* prConfig, SceUID fd) { if (prConfig == NULL) { return COLORCONFIG_NULLPTR; } sceIoWrite(fd, &prConfig->background, sizeof(u32)); sceIoWrite(fd, &prConfig->text, sizeof(u32)); return COLORCONFIG_SUCCESS; }
// 0244 void printf_char(void *ctx, int ch) { dbg_printf("Calling %s\n", __FUNCTION__); if (ch == 0x200) { *(short*)(ctx + 2) = 0; return; } if (ch == 0x201) { // 031C short cnt = *(short*)(ctx + 2); if (cnt <= 0) return; if (sceKernelDipsw(59) == 1) sceKernelDebugWrite(*(short*)(ctx + 0), ctx + 4, *(short*)(ctx + 2)); else { short fd = *(short*)(ctx + 0); if (fd == STDOUT) fd = g_stdout; // 0348 if (fd == STDERR) fd = g_stderr; // 0354 sceIoWrite(fd, ctx + 4, *(short*)(ctx + 2)); } return; } if (ch == '\n') { // 030C printf_char(ctx, '\r'); } // 027C (*(short*)(ctx + 2))++; *(char*)(ctx + 3 + *(short*)(ctx + 2)) = ch; if (ch == '\200') { short fd = *(short*)(ctx + 0); // 02AC if (sceKernelDipsw(59) == 1) { // 02F8 sceKernelDebugWrite(fd, ctx + 4, *(short*)(ctx + 2)); } else { if (fd == STDOUT) fd = g_stdout; // 02C8 if (fd == STDERR) fd = g_stderr; // 02D4 sceIoWrite(fd, ctx + 4, *(short*)(ctx + 2)); } *(short*)(ctx + 2) = 0; } }
void PBPParse::Parse(const char *file){ fid = sceIoOpen(file, PSP_O_RDONLY, 0777); sceIoMkdir("ms0:/TMP", 0777); if (fid >= 0) { if (sceIoRead(fid, &header, sizeof(PBPHeader)) == sizeof(PBPHeader)){ char *temp = (char*)malloc(header.icon0 - header.sfo); sceIoLseek(fid, header.sfo, PSP_SEEK_SET); sceIoRead(fid, temp, header.icon0 - header.sfo); SceUID sfoFile = sceIoOpen("ms0:/TMP/PARAM.SFO", PSP_O_CREAT | PSP_O_WRONLY, 0777); sceIoWrite(sfoFile, temp, header.icon0 - header.sfo); sceIoClose(sfoFile); free(temp); sfo.Parse("ms0:/TMP/PARAM.SFO"); temp = (char*)malloc(header.icon1 - header.icon0); sceIoLseek(fid, header.icon0, PSP_SEEK_SET); sceIoRead(fid, temp, header.icon1 - header.icon0); SceUID icoFile = sceIoOpen("ms0:/TMP/ICON0.PNG", PSP_O_CREAT | PSP_O_WRONLY, 0777); sceIoWrite(icoFile, temp, header.icon1 - header.icon0); sceIoClose(icoFile); if (header.icon1 - header.icon0 > 0){ OSL_IMAGE *ico = oslLoadImageFilePNG("ms0:/TMP/ICON0.PNG", OSL_IN_RAM | OSL_SWIZZLED, OSL_PF_5650); icon = oslScaleImageCreate(ico, OSL_IN_RAM, 64, 64, OSL_PF_5650); oslDeleteImage(ico); oslWriteImageFilePNG(icon, "ms0:/TMP/ICON0.PNG", 0); } else{ icon = oslCreateImageCopy(defaultUNKN, OSL_IN_RAM); } free(temp); temp = (char*)malloc(header.snd - header.pic1); sceIoLseek(fid, header.pic1, PSP_SEEK_SET); sceIoRead(fid, temp, header.snd - header.pic1); SceUID picFile = sceIoOpen("ms0:/TMP/PIC1.PNG", PSP_O_CREAT | PSP_O_WRONLY, 0777); sceIoWrite(picFile, temp, header.snd - header.pic1); sceIoClose(picFile); if (header.snd - header.pic1 > 0){ pic = oslLoadImageFilePNG("ms0:/TMP/PIC1.PNG", OSL_IN_RAM, OSL_PF_8888); OSL_IMAGE *tmpPic = oslScaleImageCreate(pic, OSL_IN_RAM, 128, 128, OSL_PF_8888); oslUnswizzleImage(tmpPic); oslWriteImageFilePNG(tmpPic, "ms0:/TMP/PIC1SC.PNG", 0); oslDeleteImage(tmpPic); oslDeleteImage(pic); //Get rid of the pic file for now, we don't need it } free(temp); sceIoClose(fid); } } }
void emulatorEmitScreenshot() { int file; if (RUNNING_ON_EMULATOR) { sceIoDevctl("kemulator:", EMULATOR_DEVCTL__EMIT_SCREENSHOT, NULL, 0, NULL, 0); } else { uint topaddr; int bufferwidth; int pixelformat; sceDisplayGetFrameBuf((void **)&topaddr, &bufferwidth, &pixelformat, 0); if (topaddr & 0x80000000) { topaddr |= 0xA0000000; } else { topaddr |= 0x40000000; } if ((file = sceIoOpen("__screenshot.bmp", PSP_O_CREAT | PSP_O_WRONLY | PSP_O_TRUNC, 0777)) >= 0) { int y, x; uint c; uint* vram_row; uint* row_buf = (uint *)malloc(512 * 4); sceIoWrite(file, &bmpHeader, sizeof(bmpHeader)); for (y = 0; y < 272; y++) { vram_row = (uint *)(topaddr + 512 * 4 * (271 - y)); for (x = 0; x < 512; x++) { c = vram_row[x]; /* row_buf[x] = ( ((extractBits(c, 0, 8)) << 0) | ((extractBits(c, 8, 8)) << 8) | ((extractBits(c, 16, 8)) << 16) | (( 0x00 ) << 24) | 0); */ row_buf[x] = ( ((extractBits(c, 16, 8)) << 0) | ((extractBits(c, 8, 8)) << 8) | ((extractBits(c, 0, 8)) << 16) | (( 0x00 ) << 24) | 0); } sceIoWrite(file, row_buf, 512 * 4); } free(row_buf); //sceIoWrite(file, (void *)topaddr, bufferwidth * 272 * 4); //sceIoFlush(); sceIoClose(file); } } }
static int save_cache(void) { int i; SceUID fd; u32 magic = get_isocache_magic(); if (g_caches == NULL) { return -33; } for(i=0; i<g_caches_cnt; ++i) { if (g_caches[i].enabled && !g_referenced[i]) { g_need_update = 1; memset(&g_caches[i], 0, sizeof(g_caches[i])); } } if(!g_need_update) { printk("%s: no need to update\n", __func__); return 0; } for(i=0; i<3; ++i) { fd = sceIoOpen(PSP_CACHE_PATH, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777); if (fd >= 0) { break; } printk("%s: open %s -> 0x%08X\n", __func__, PSP_CACHE_PATH, fd); fd = sceIoOpen(PSPGO_CACHE_PATH, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777); if (fd >= 0) { break; } printk("%s: open %s -> 0x%08X\n", __func__, PSPGO_CACHE_PATH, fd); } if (fd < 0) { return -21; } sceIoWrite(fd, &magic, sizeof(magic)); sceIoWrite(fd, g_caches, sizeof(g_caches[0])*g_caches_cnt); sceIoClose(fd); g_need_update = 0; return 0; }
static void neogeo_exit(void) { SceUID fd; char path[MAX_PATH]; video_set_mode(32); video_clear_screen(); ui_popup_reset(); video_clear_screen(); msg_screen_init(WP_LOGO, ICON_SYSTEM, TEXT(EXIT_EMULATION2)); msg_printf(TEXT(PLEASE_WAIT2)); #ifdef ADHOC if (!adhoc_enable) #endif { sprintf(path, "%smemcard/%s.bin", launchDir, game_name); if ((fd = sceIoOpen(path, PSP_O_WRONLY|PSP_O_CREAT, 0777)) >= 0) { sceIoWrite(fd, neogeo_memcard, 0x800); sceIoClose(fd); } sprintf(path, "%snvram/%s.nv", launchDir, game_name); if ((fd = sceIoOpen(path, PSP_O_WRONLY|PSP_O_CREAT, 0777)) >= 0) { swab(neogeo_sram16, neogeo_sram16, 0x2000); sceIoWrite(fd, neogeo_sram16, 0x2000); sceIoClose(fd); } #ifdef COMMAND_LIST free_commandlist(); #endif if (neogeo_save_sound_flag) option_sound_enable = 1; save_gamecfg(game_name); } msg_printf(TEXT(DONE2)); #ifdef ADHOC if (adhoc_enable) adhocTerm(); #endif show_exit_screen(); }
int makeDiff( const char * file, const char * ori, int heap_id, int ctf ) { log( "detect %s, start to make diff!\n", file ); u8 * buf = NULL, * buf_ori = NULL; int bytes = readPrx( file, heap_id, &buf ); if ( bytes < 0 ) { log( "failed in read %s!\n", file ); return -1; } if ( readPrx( ori, heap_id, &buf_ori ) != bytes ) { log( "failed in read %s!\n", ori ); sceKernelFreeHeapMemory( heap_id, buf ); sceKernelFreeHeapMemory( heap_id, buf_ori ); return -1; } int sub = ( strstr( file, diff_files[1] ) ? 0xA0: 0xC0 ); int diff_count = 0; unsigned int offset = 0, rec_attr[2]; int rec = 0; memset( rec_attr, 0, 8 ); while( offset < bytes ) { if ( buf[offset] != buf_ori[offset] ) { if ( !rec ) { rec_attr[0] = offset - sub; rec_attr[1] = 0; rec = 1; } rec_attr[1] ++; } else { if ( rec ) { log( "diff_start: %08x\nsize: %08x\n", rec_attr[0], rec_attr[1] ); sceIoWrite( ctf, rec_attr, 8 ); sceIoWrite( ctf, &buf[rec_attr[0] + sub], rec_attr[1] ); diff_count ++; rec = 0; } } offset ++; } sceKernelFreeHeapMemory( heap_id, buf_ori ); sceKernelFreeHeapMemory( heap_id, buf ); return diff_count; }
void __pspgl_dlist_dump (unsigned long *cmd_buf, unsigned long len) { unsigned long header [3]; int fd; header[0] = PSPGL_GE_DUMP_DLIST; header[1] = sizeof(header) + len * sizeof(cmd_buf[0]); header[2] = (unsigned long) cmd_buf; fd = sceIoOpen(PSPGL_GE_DUMPFILE, PSP_O_CREAT | PSP_O_APPEND | PSP_O_WRONLY, 0644); sceIoWrite(fd, header, sizeof(header)); sceIoWrite(fd, (void *) cmd_buf, len * sizeof(cmd_buf[0])); sceIoClose(fd); }
int write_file(const char *path, unsigned char *buf, int size) { SceUID fd; int ret; fd = sceIoOpen(path, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777); if (fd < 0) { goto error; } ret = sceIoWrite(fd, buf, size); if (ret < 0) { goto error; } sceIoClose(fd); return 0; error: if (fd >= 0) sceIoClose(fd); return -1; }
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; }
static void receive_file(ClientInfo *client, const char *path) { unsigned char *buffer; SceUID fd; unsigned int bytes_recv; DEBUG("Opening: %s\n", path); if ((fd = sceIoOpen(path, PSP2_O_CREAT | PSP2_O_WRONLY | PSP2_O_TRUNC, 0777)) >= 0) { buffer = malloc(FILE_BUF_SIZE); if (buffer == NULL) { client_send_ctrl_msg(client, "550 Could not allocate memory.\n"); return; } client_open_data_connection(client); client_send_ctrl_msg(client, "150 Opening Image mode data transfer.\n"); while ((bytes_recv = client_send_recv_raw(client, buffer, FILE_BUF_SIZE)) > 0) { sceIoWrite(fd, buffer, bytes_recv); } sceIoClose(fd); free(buffer); client_send_ctrl_msg(client, "226 Transfer completed.\n"); client_close_data_connection(client); } else { client_send_ctrl_msg(client, "550 File not found.\n"); } }
void printResult(char *name, int durationMillis, float pspDurationMillis) { char s[1000]; sprintf(s, "%-25s: %5d ms (%5.0f%%) @ %d MHz\n", name, durationMillis, pspDurationMillis / durationMillis * 100, scePowerGetCpuClockFrequencyInt()); // pspDebugScreenPrintf("%s", s); sceIoWrite(logFd, s, strlen(s)); }
static void write_line_buffer_to_file(SceUID fd)/*FILE *fp*/ /*, char *str_buf*/ { char *str_pointer; str_pointer = my_file_line_buffer256; // const char k = 13; // fprintf(fp, "%s%c\n", str_pointer, k); unsigned int len; len = 0; /* 文字列終端を調べる。 */ { string_retry:/*(もう一度)*/ if (0 == (*str_pointer)) /* 文字列終端か。 */ { goto string_terminate; } #if (0)/*(エラーチェック)*/ // if (253 < len)/* 長すぎる場合は強制打ち切り。(254==0x0d, 255==0x0a, [256]なので[255]まで使える。) */ if (250 < len)/* テキトー */ { goto string_terminate; } #endif len++; str_pointer++; goto string_retry; string_terminate:/*(調査完了)*/ ; } /* 差分氏模倣風のファイル形式が[CR+LF]だったので互換を取る。 */ *str_pointer = 0x0d; len++; str_pointer++;/*[CR]*/ *str_pointer = 0x0a; len++; str_pointer++;/*[LF]*/ // fprintf(fp, "%s\n", str_pointer); sceIoWrite(fd, my_file_line_buffer256, len);/*sizeof(int)*/ /**save_data_size*/ /*, 1, fp*/ }
u32 sceIoWriteAsync(int id, void *data_ptr, int size) { DEBUG_LOG(HLE, "sceIoWriteAsync(%d)", id); sceIoWrite(id, data_ptr, size); __IoCompleteAsyncIO(id); return 0; }
bool save_passwords(void) { password *pwd; SceUID fd; char path[PATH_MAX]; u32 magic; STRCPY_S(path, scene_appdir()); STRCAT_S(path, "password.lst"); rc4_prepare_key((u8 *) CRYPT_KEY, sizeof(CRYPT_KEY) - 1, &g_key); fd = sceIoOpen(path, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777); if (fd < 0) { return false; } magic = CRYPT_MAGIC; sceIoWrite(fd, &magic, sizeof(magic)); for (pwd = g_pwd_head.next; pwd != NULL; pwd = pwd->next) { write_chars(fd, pwd->b->ptr, strlen(pwd->b->ptr)); write_chars(fd, "\r\n", sizeof("\r\n") - 1); } sceIoClose(fd); return true; }
void checkIo(int doDispatch) { char temp[128]; SceUID fd = sceIoOpen("dispatch.prx", PSP_O_RDONLY, 0777); dispatchCheckpoint("sceIoOpen: %08x", fd >= 0 ? 1 : fd); dispatchCheckpoint("sceIoRead: %08x", sceIoRead(fd, temp, sizeof(temp))); dispatchCheckpoint("sceIoClose: %08x", sceIoClose(fd)); int state; if (doDispatch) { ++ignoreResched; state = sceKernelSuspendDispatchThread(); dispatchCheckpoint("sceKernelSuspendDispatchThread: %08x", state); } fd = sceIoOpen("dispatch.prx", PSP_O_RDONLY, 0777); dispatchCheckpoint("sceIoOpen: %08x", fd >= 0 ? 1 : fd); dispatchCheckpoint("sceIoRead: %08x", sceIoRead(fd, temp, sizeof(temp))); dispatchCheckpoint("sceIoClose: %08x", sceIoClose(fd)); if (doDispatch) { dispatchCheckpoint("sceKernelResumeDispatchThread: %08x", sceKernelResumeDispatchThread(state)); --ignoreResched; } SceInt64 res = -1; int result = -1; fd = sceIoOpenAsync("dispatch.prx", PSP_O_RDONLY, 0777); dispatchCheckpoint("sceIoOpenAsync: %08x", fd >= 0 ? 1 : fd); if (doDispatch) { ++ignoreResched; state = sceKernelSuspendDispatchThread(); dispatchCheckpoint("sceKernelSuspendDispatchThread: %08x", state); } result = sceIoPollAsync(fd, &res); dispatchCheckpoint("sceIoPollAsync: %08x / %016llx", result, res >= 0 ? 1LL : res); result = sceIoGetAsyncStat(fd, 1, &res); dispatchCheckpoint("sceIoGetAsyncStat: %08x / %016llx", result, res >= 0 ? 1LL : res); result = sceIoGetAsyncStat(fd, 0, &res); dispatchCheckpoint("sceIoGetAsyncStat: %08x / %016llx", result, res >= 0 ? 1LL : res); result = sceIoWaitAsync(fd, &res); dispatchCheckpoint("sceIoWaitAsync: %08x / %016llx", result, res >= 0 ? 1LL : res); if (doDispatch) { dispatchCheckpoint("sceKernelResumeDispatchThread: %08x", sceKernelResumeDispatchThread(state)); --ignoreResched; } result = sceIoWaitAsync(fd, &res); dispatchCheckpoint("sceIoWaitAsync: %08x / %016llx", result, res >= 0 ? 1LL : res); if (doDispatch) { ++ignoreResched; state = sceKernelSuspendDispatchThread(); dispatchCheckpoint("sceKernelSuspendDispatchThread: %08x", state); } dispatchCheckpoint("sceIoRead: %08x", sceIoRead(fd, temp, sizeof(temp))); dispatchCheckpoint("sceIoWrite: %08x", sceIoWrite(1, "Hello.", sizeof("Hello."))); if (doDispatch) { dispatchCheckpoint("sceKernelResumeDispatchThread: %08x", sceKernelResumeDispatchThread(state)); --ignoreResched; } dispatchCheckpoint("sceIoCloseAsync: %08x", sceIoCloseAsync(fd)); result = sceIoWaitAsync(fd, &res); dispatchCheckpoint("sceIoWaitAsync: %08x / %016llx", result, res); }
void writeLog(const char *s, int length) { int forceBuffering = (dobuffering++ % 60) != 0; int restLength = commonInfo->maxLogBufferLength - commonInfo->logBufferLength; if (restLength < 512) forceBuffering = 0; if (commonInfo->inWriteLog || forceBuffering) { appendToLogBuffer(s, length); return; } commonInfo->inWriteLog++; if (!commonInfo->logKeepOpen) { openLogFile(); } flushLogBuffer(); if (sceIoWrite(commonInfo->logFd, s, length) < 0) { // Can't write to the log file right now, probably because the interrupts are disabled. // Save the log string for later output. appendToLogBuffer(s, length); } else { flushLogBuffer(); } if (!commonInfo->logKeepOpen) { closeLogFile(); } commonInfo->inWriteLog--; }
int copy_file(char *input, char *output) { SceUID i = sceIoOpen(input, PSP_O_RDONLY, 0777); if (i < 0) return -1; sceIoRemove(output); SceUID o = sceIoOpen(output, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777); if (o < 0) return -1; int read; while ((read = sceIoRead(i, buf, 16384)) > 0) { sceIoWrite(o, buf, read); } sceIoClose(i); sceIoClose(o); return 0; }
static void pspgl_ge_writefile (void *buf, unsigned long len) { int fd = sceIoOpen(PSPGL_GE_DUMPFILE, PSP_O_CREAT | PSP_O_APPEND | PSP_O_WRONLY, 0644); sceIoWrite(fd, buf, len); sceIoClose(fd); }
ssize_t filestream_write(RFILE *stream, const void *s, size_t len) { if (!stream) return -1; #if defined(VITA) || defined(PSP) return sceIoWrite(stream->fd, s, len); #elif defined(__CELLOS_LV2__) uint64_t bytes_written; if (cellFsWrite(stream->fd, s, len, &bytes_written) != CELL_FS_SUCCEEDED) return -1; return bytes_written; #else #if defined(HAVE_BUFFERED_IO) if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0) return fwrite(s, 1, len, stream->fp); else #endif #ifdef HAVE_MMAP if (stream->hints & RFILE_HINT_MMAP) return -1; else #endif return write(stream->fd, s, len); #endif }
int FileCopy(char* srcPath, char* destPath, char* fileName) { SceIoStat fileStat; char path[258]; sprintf(path,"%s/%s",srcPath, fileName); if(sceIoGetstat(path, &fileStat) < 0) return -1; u8* data = malloc(fileStat.st_size); SceUID fileId = sceIoOpen(path, PSP_O_RDONLY, 0777); if(fileId < 0) { printf("Fail opening %s\n",path); free(data); return -1; } sceIoRead(fileId, data, fileStat.st_size); sceIoClose(fileId); sprintf(path,"%s/%s",destPath, fileName); fileId = sceIoOpen(path, PSP_O_WRONLY | PSP_O_CREAT, 0777); if(fileId < 0) { printf("Fail opening %s\n",path); return -1; } sceIoWrite(fileId, data, fileStat.st_size); sceIoClose(fileId); free(data); return 0; }
int hcWriteFile(char* file, void* buffer, int size) { int i; int pathlen = 0; char path[128]; // because I'm so lazy, I need folders created "on the fly" // this does so, create every folder in the path of the // file we are to save. // A little bruty forcy, yah, but it does the job :-D for (i = 1; i < (strlen(file)); i++) { if (strncmp(file + i - 1, "/", 1) == 0) { pathlen = i - 1; strncpy(path, file, pathlen); path[pathlen] = 0; sceIoMkdir(path, 0777); } } // now up to the file write.... SceUID fd = sceIoOpen(file, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777); if (fd < 0) { return -1; } int written = sceIoWrite(fd, buffer, size); if (sceIoClose(fd) < 0) return -1; return written; }
static void debugOut(const char *text) { int fd = sceIoOpen("debug.txt", PSP_O_WRONLY|PSP_O_CREAT|PSP_O_APPEND, 0777); sceIoWrite(fd, text, strlen(text)); sceIoClose(fd); }
void my_print(const char* str) { int fdLog = sceIoOpen("ms0:/err.txt", PSP_O_WRONLY|PSP_O_APPEND, 0777); if (fdLog > 0) { sceIoWrite(fdLog, (void*)str, strlen(str)); sceIoClose(fdLog); } }
static int write_char(SceUID fd, char c) { u8 prg; prg = rc4_prga(&g_key); c ^= prg; return sceIoWrite(fd, &c, 1); }
static void _vfsceUnmap(struct VFile* vf, void* memory, size_t size) { struct VFileSce* vfsce = (struct VFileSce*) vf; SceOff cur = sceIoLseek(vfsce->fd, 0, SEEK_CUR); sceIoLseek(vfsce->fd, 0, SEEK_SET); sceIoWrite(vfsce->fd, memory, size); sceIoLseek(vfsce->fd, cur, SEEK_SET); sceIoSyncByFd(vfsce->fd); mappedMemoryFree(memory, size); }
extern void conf_save() { int fd = sceIoOpen(CONFIG_DIR, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777); if(fd >= 0) { sceIoWrite(fd, &config, sizeof(config)); } sceIoClose(fd); }