Error DirAccessFlash::change_dir(String p_dir) { if (p_dir==".") return OK; if (p_dir.is_rel_path()) current_dir+="/"+p_dir; else current_dir=fix_path(p_dir); current_dir=current_dir.simplify_path(); if (current_dir.length()>1 && current_dir.ends_with("/") && !current_dir.ends_with("//")) current_dir=current_dir.substr(0,current_dir.length()-1); return OK; };
/* concatenate directory / file */ char *join_path(char *buffer, const char *dir, const char *filename) { int l = strlen(dir); if (l) { memcpy(buffer, dir, l); if (!IS_SLASH(buffer[l-1])) buffer[l++] = '\\'; } if (filename) { while (IS_SLASH(filename[0])) ++filename; strcpy(buffer + l, filename); } else { buffer[l] = 0; fix_path(buffer); } return buffer; }
Boolean_t text_rename(struct text *text, const char *path0) { char *path = fix_path(path0); struct text *b; struct view *view; fd_t fd; if (!path) return FALSE; for (b = text; b; b = b->next) if (b->path && !strcmp(b->path, path)) return FALSE; errno = 0; if ((fd = open(path, O_CREAT|O_RDWR, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0) { message("%s: can't create", path_format(path)); RELEASE(path); return FALSE; } if (text->flags & TEXT_CREATED) { unlink(text->path); text->flags &= ~(TEXT_CREATED | TEXT_SCRATCH); } /* Do not truncate or overwrite yet. */ text->flags |= TEXT_SAVED_ORIGINAL; text->flags &= ~TEXT_RDONLY; text_dirty(text); close(text->fd); if (text->clean) { munmap(text->clean, text->clean_bytes); text->clean = NULL; } text->fd = fd; grab_mtime(text); RELEASE(text->path); text->path = path; keyword_init(text); for (view = text->views; view; view = view->next) view_name(view); return TRUE; }
bool FileAccessJAndroid::file_exists(const String& p_path) { JNIEnv *env = ThreadAndroid::get_env(); String path=fix_path(p_path).simplify_path(); if (path.begins_with("/")) path=path.substr(1,path.length()); else if (path.begins_with("res://")) path=path.substr(6,path.length()); jstring js = env->NewStringUTF(path.utf8().get_data()); int res = env->CallIntMethod(io,_file_open,js,false); if (res<=0) return false; env->CallVoidMethod(io,_file_close,res); env->DeleteLocalRef(js); return true; }
uint64_t FileAccessWindows::_get_modified_time(const String& p_file) { String file=fix_path(p_file); if (file.ends_with("/") && file!="/") file=file.substr(0,file.length()-1); struct _stat st; int rv = _wstat(file.c_str(), &st); if (rv == 0) { return st.st_mtime; } else { print_line("no access to "+file ); } ERR_FAIL_V(0); };
int do_get(char *argv[]) { char *inside = argv[0], *outside = argv[1]; char path[128]; int len, fd, offset = 0, val = 0; if ((fd = open(outside, O_WRONLY|O_CREAT|O_TRUNC, 0777)) < 0) return fd; sprintf(path, "%s/%s", cwd, inside); fix_path(path); while ((len = hw3_ops.read(path, blkbuf, blksiz, offset, NULL)) > 0) { if ((val = write(fd, blkbuf, len)) != len) break; offset += len; } close(fd); return (val >= 0) ? 0 : val; }
Error FileAccessAndroid::_open(const String& p_path, int p_mode_flags) { String path=fix_path(p_path).simplify_path(); if (path.begins_with("/")) path=path.substr(1,path.length()); else if (path.begins_with("res://")) path=path.substr(6,path.length()); ERR_FAIL_COND_V(p_mode_flags&FileAccess::WRITE,ERR_UNAVAILABLE); //can't write on android.. a=AAssetManager_open(asset_manager,path.utf8().get_data(),AASSET_MODE_STREAMING); if (!a) return ERR_CANT_OPEN; //ERR_FAIL_COND_V(!a,ERR_FILE_NOT_FOUND); len=AAsset_getLength(a); pos=0; eof=false; return OK; }
int test_load(int argc, char** argv) { if (argc < 1) { LOGE("Nothing to load!"); return -1; } const char* file_path; int offset_block = 0; int blocks = 0; if (argc > 0) { file_path = (const char*)fix_path(argv[0]); argc--, argv++; } if (argc > 0) { offset_block = atoi(argv[0]); argc--, argv++; } if (argc > 0) { blocks = atoi(argv[0]); } return load_file(file_path, offset_block, blocks); }
bool create_folder(const char *path) { // Sanitize path char folderpath[4096]; char folderbuf[4096]; strncpy(folderpath, path, sizeof(folderpath)); folderpath[sizeof(folderpath)-1] = '\0'; fix_path(folderpath); folderbuf[0] = '\0'; // Iterate and create const char *ptr = folderpath; unsigned int pathItr = 0; while((ptr = strchr(ptr, '/')) != NULL) { if (ptr - folderpath > 0) { strncpy(folderbuf, folderpath, ptr - folderpath); folderbuf[(ptr-folderpath)] = 0; } if (strlen(folderbuf) > 0 && !folder_exists(folderbuf)) { if (mkdir(folderbuf, 0700) != 0) return false; } ptr++; } // Sort out final / if (strlen(path) > 0 && !folder_exists(path)) { if (mkdir(path, 0700) != 0) return false; } return true; }
char *parse_http_request() { char buffer[1024]; char *path; char *q; printf("[debug] buffer is at 0x%08x :-)\n", buffer); if(read(0, buffer, sizeof(buffer)) <= 0) errx(0, "Failed to read from remote host"); if(memcmp(buffer, "GET ", 4) != 0) errx(0, "Not a GET request"); path = &buffer[4]; q = strchr(path, ' '); if(! q) errx(0, "No protocol version specified"); *q++ = 0; if(strncmp(q, "HTTP/1.1", 8) != 0) errx(0, "Invalid protocol"); fix_path(path); printf("trying to access %s\n", path); return path; }
int do_put(char *argv[]) { char *outside = argv[0], *inside = argv[1]; char path[128]; int len, fd, offset = 0, val; if ((fd = open(outside, O_RDONLY, 0)) < 0) return fd; sprintf(path, "%s/%s", cwd, inside); fix_path(path); if ((val = hw3_ops.create(path, 0777, 0)) != 0) return val; while ((len = read(fd, blkbuf, blksiz)) > 0) { val = hw3_ops.write(path, blkbuf, len, offset, NULL); if (val != len) break; offset += len; } close(fd); return (val >= 0) ? 0 : val; }
Error DirAccessWindows::change_dir(String p_dir) { GLOBAL_LOCK_FUNCTION p_dir = fix_path(p_dir); wchar_t real_current_dir_name[2048]; GetCurrentDirectoryW(2048, real_current_dir_name); String prev_dir = real_current_dir_name; SetCurrentDirectoryW(current_dir.c_str()); bool worked = (SetCurrentDirectoryW(p_dir.c_str()) != 0); String base = _get_root_path(); if (base != "") { GetCurrentDirectoryW(2048, real_current_dir_name); String new_dir; new_dir = String(real_current_dir_name).replace("\\", "/"); if (!new_dir.begins_with(base)) { worked = false; } } if (worked) { GetCurrentDirectoryW(2048, real_current_dir_name); current_dir = real_current_dir_name; // TODO, utf8 parser current_dir = current_dir.replace("\\", "/"); } //else { SetCurrentDirectoryW(prev_dir.c_str()); //} return worked ? OK : ERR_INVALID_PARAMETER; }
} //else { SetCurrentDirectoryW(prev_dir.c_str()); //} return worked ? OK : ERR_INVALID_PARAMETER; } Error DirAccessWindows::make_dir(String p_dir) { GLOBAL_LOCK_FUNCTION if (p_dir.is_rel_path()) p_dir = get_current_dir().plus_file(p_dir); p_dir = fix_path(p_dir); p_dir = p_dir.replace("/", "\\"); bool success; int err; p_dir = "\\\\?\\" + p_dir; //done according to // https://msdn.microsoft.com/en-us/library/windows/desktop/aa363855(v=vs.85).aspx success = CreateDirectoryW(p_dir.c_str(), NULL); err = GetLastError(); if (success) { return OK; };
static wchar_t* readlink(wchar_t* path) { size_t szbuf = 0; wchar_t* result = path; char* cygbuf = NULL; byte* buffer = NULL; pcyglink slink = NULL; verbose(L"Checking %s for symbolic link..", path); // Make sure path is a file flagged as a system file. if(!is_file(path) || !has_system_attr(path)) goto cleanup; // Allocate our buffer and read the file into it. buffer = file_to_buffer(path, &szbuf); // Check if our buffer contains a symbolic link. if(!is_buf_symlink(buffer, szbuf)) goto cleanup; // If we get to this point, we're definitely working // with a symbolic link, so cast it to the struct. verbose(L"Detected symbolic link.."); slink = (pcyglink)buffer; // Get the string length of our link's target. szbuf = wcslen(slink->target); if(szbuf == 0) { fatal(1, L"Empty path found as target of the symbolic link at %s.", path); } // Before converting it, we need to check whether it's a relative // or absolute file path. if(slink->target[0] != L'/') { verbose(L"Symbolic link target resolved to a relative path. Prefixing bin dir.."); virtRootCyg = fix_path(virtRootWin); // len(virtualenv root) + len('/bin/') + len(target) szbuf += wcslen(virtRootCyg) + 5; result = walloc(szbuf++); swprintf(result, szbuf, L"%s/bin/%s", virtRootCyg, slink->target); } else { // Duping it to allow freeing the memory a few // lines later without issue. verbose(L"Symbolic link target appears to be an absolute path. Continuing.."); result = _wcsdup(slink->target); } // Convert it to a ANSI string to allow converting // it with cygwin. cygbuf = xalloc(szbuf, sizeof(char)); wcstombs(cygbuf, result, szbuf+1); xfree(result); if(!(result = fix_path_type((void*)cygbuf, false, CCP_POSIX_TO_WIN_A))) { result = path; goto cleanup; } verbose_step(L"readlink(x)"); verbose_step(L" x -> %s", path); verbose_step(L" r <- %s", result); cleanup: xfree(buffer); xfree(cygbuf); #ifdef WITHOUT_ENVVARS xfree(virtRootCyg); #endif return result; }
LYTDirectoryPackage::LYTDirectoryPackage(QString path, QObject *parent) : LYTPackageBase(parent) { qWarning("LYTDirectoryPackage is currently unmaintained, you probably shouldn't use it"); QDir fix_path(path); this->m_path = fix_path.absolutePath(); }
Error FileAccessWindows::_open(const String &p_path, int p_mode_flags) { path_src = p_path; path = fix_path(p_path); if (f) close(); const wchar_t *mode_string; if (p_mode_flags == READ) mode_string = L"rb"; else if (p_mode_flags == WRITE) mode_string = L"wb"; else if (p_mode_flags == READ_WRITE) mode_string = L"rb+"; else if (p_mode_flags == WRITE_READ) mode_string = L"wb+"; else return ERR_INVALID_PARAMETER; /* pretty much every implementation that uses fopen as primary backend supports utf8 encoding */ struct _stat st; if (_wstat(path.c_str(), &st) == 0) { if (!S_ISREG(st.st_mode)) return ERR_FILE_CANT_OPEN; }; #ifdef TOOLS_ENABLED // Windows is case insensitive, but all other platforms are sensitive to it // To ease cross-platform development, we issue a warning if users try to access // a file using the wrong case (which *works* on Windows, but won't on other // platforms). if (p_mode_flags == READ) { WIN32_FIND_DATAW d = { 0 }; HANDLE f = FindFirstFileW(path.c_str(), &d); if (f) { String fname = d.cFileName; if (fname != String()) { String base_file = path.get_file(); if (base_file != fname && base_file.findn(fname) == 0) { WARN_PRINTS("Case mismatch opening requested file '" + base_file + "', stored as '" + fname + "' in the filesystem. This file will not open when exported to other case-sensitive platforms."); } } FindClose(f); } } #endif if (is_backup_save_enabled() && p_mode_flags & WRITE && !(p_mode_flags & READ)) { save_path = path; path = path + ".tmp"; } _wfopen_s(&f, path.c_str(), mode_string); if (f == NULL) { last_error = ERR_FILE_CANT_OPEN; return ERR_FILE_CANT_OPEN; } else { last_error = OK; flags = p_mode_flags; return OK; } }
int do_mkdir(char *argv[]) { char path[128]; sprintf(path, "%s/%s", cwd, argv[0]); return hw3_ops.mkdir(fix_path(path), 0777); }
int do_lsdashl1(char *argv[]) { char path[128]; sprintf(path, "%s/%s", cwd, argv[0]); return _lsdashl(fix_path(path)); }
dir_stream = opendir(current_dir.utf8().get_data()); //chdir(real_current_dir_name); if (!dir_stream) return ERR_CANT_OPEN; //error! return OK; } bool DirAccessUnix::file_exists(String p_file) { GLOBAL_LOCK_FUNCTION if (p_file.is_rel_path()) p_file = current_dir.plus_file(p_file); p_file = fix_path(p_file); struct stat flags; bool success = (stat(p_file.utf8().get_data(), &flags) == 0); if (success && S_ISDIR(flags.st_mode)) { success = false; } return success; } bool DirAccessUnix::dir_exists(String p_dir) { GLOBAL_LOCK_FUNCTION
struct view *view_open(const char *path0) { struct view *view; struct text *text; struct stat statbuf; char *path = fix_path(path0); if (!path) return NULL; for (text = text_list; text; text = text->next) if (text->path && !strcmp(text->path, path)) { for (view = text->views; view; view = view->next) if (!view->window) goto done; view = view_create(text); goto done; } view = text_create(path, 0); text = view->text; errno = 0; if (stat(path, &statbuf)) { if (errno != ENOENT) { message("%s: can't stat", path_format(path)); goto fail; } if (read_only) { message("%s: can't create in read-only mode", path_format(path)); goto fail; } errno = 0; text->fd = open(path, O_CREAT|O_TRUNC|O_RDWR, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); if (text->fd < 0) { message("%s: can't create", path_format(path)); goto fail; } text->flags |= TEXT_CREATED; } else { if (!S_ISREG(statbuf.st_mode)) { message("%s: not a regular file", path_format(path)); goto fail; } if (!read_only) text->fd = open(path, O_RDWR); if (text->fd < 0) { errno = 0; text->flags |= TEXT_RDONLY; text->fd = open(path, O_RDONLY); if (text->fd < 0) { message("%s: can't open", path_format(path)); goto fail; } } clean_mmap(text, statbuf.st_size, PROT_READ); if (!text->clean) { text->buffer = buffer_create(path); if (old_fashioned_read(text) < 0) goto fail; grab_mtime(text); } view->bytes = text->buffer ? buffer_bytes(text->buffer) : text->clean_bytes; scan(view); text_forget_undo(text); } goto done; fail: view_close(view); view = NULL; done: RELEASE(path); return view; }
int do_rmdir(char *argv[]) { char path[128]; sprintf(path, "%s/%s", cwd, argv[0]); return hw3_ops.rmdir(fix_path(path)); }
//----------------------------------------------------------------------------- void ConfPrx::_assign( const char* pred, const char* val, int line) { char lpred[256]; char loco[256]; ::strcpy(loco,val); ::strcpy(lpred,pred); try { if(_section.substr(1,::strlen(__VERSION)) == __VERSION) { BIND(_glb,runfrom); BIND(_glb,slog); BIND(_glb,nlogbytes); BIND(_glb,sessiontime); BIND(_glb,dnsssltout); BIND(_glb,bouncemax); BIND(_glb,authurl); BIND(_glb,usercontrol); BIND(_glb,reloadacls); BIND(_glb, hostsfile); BIND(_glb, hostsfilerule); BIND(_glb, openacl); //overwrites the non openacl ports. BIND(_glb, admins); BIND(_glb, maxrecs); BIND(_glb, domrecs); BIND(_glb, banned_ips); BIND(_glb, tickfile) BIND(_glb, jumpip); BIND(_glb, subscribers); if(lpred[0]=='}') { if(!_glb.signature.empty()) { fix_path(_glb.signature); // _glb.signaturegz=_glb.signature.append(".gz"); std::ifstream t(_glb.signature); std::stringstream buffer; buffer << t.rdbuf(); _glb.signature = buffer.str(); t.close(); } _glb.blog=0; if(_glb.slog=="A") { _glb.blog=0xFFFFFFFF; } else { _glb.blog |= _glb.slog.find('I') == string::npos ? 0 : 0x1; _glb.blog |= _glb.slog.find('W') == string::npos ? 0 : 0x2; _glb.blog |= _glb.slog.find('E') == string::npos ? 0 : 0x4; _glb.blog |= _glb.slog.find('T') == string::npos ? 0 : 0x8; _glb.blog |= _glb.slog.find('D') == string::npos ? 0 : 0x10; _glb.blog |= _glb.slog.find('X') == string::npos ? 0 : 0x20; _glb.blog |= _glb.slog.find('H') == string::npos ? 0 : 0x40; } _blog = _glb.blog; for(auto & f : _glb.jumpip) { const SADDR_46& k=(f).first; SADDR_46& v=(f).second; GLOGI("Jump: " << IP2STR(k) <<" -> " << IP2STR(v) ); } _glb.sessiontime *= 60; _glb.dnsssltout *= 60; if(!_glb.authurl.empty()) _glb.authurl_ip = fromstringip(_glb.authurl ); else _glb.authurl_ip = fromstringip("127.0.0.1:80"); if(!_glb.tickfile.empty()) { FILE* pf = fopen(_glb.tickfile.c_str(),"wb"); if(pf) { ::fputs("#",pf); ::fclose(pf); } } } // eo section } if(_section == "[port]") { BIND(_ports,pending); BIND(_ports,bindaddr); BIND(_ports,port); BIND(_ports,blocking); BIND(_ports,socks); BIND(_ports,clientisssl); BIND(_ports,hostisssl); BIND(_ports, openacl); BIND(_ports, authtoken); BIND(_ports, redirect); BIND(_ports, conport); if(lpred[0]=='}') { if(_ports.openacl==-1) // open port, make it as global ACL. _ports.openacl = _glb.openacl; GLOGD("ACL:" <<_ports.socks <<"/" << _ports.port << ": " << _ports.openacl) ::fix(_ports.pending, 32, 256); ::fix(_ports.port, (size_t)64, (size_t)65534); if(_ports.socks=="DNSSOCK" || _ports.socks=="PASSTRU") { if(!_ports.redirect.empty()) { _ports.toaddr=fromstringip(_ports.redirect.c_str()); GLOGD("Port:" << _ports.port << " forward to " << _ports.toaddr.c_str() << ":" << _ports.toaddr.port()); } } // vector<Redirs> redirs; // vector<string> overs; _listeners.insert(_ports); _ports.clear(); } } if(_section == "[pool]") { _bind(lpred, "min_threads",_pool.min_threads, val); _bind(lpred, "max_threads",_pool.max_threads, val); _bind(lpred, "clients_perthread",_pool.clients_perthread, val); _bind(lpred, "min_queue",_pool.min_queue, val); _bind(lpred, "max_queue",_pool.max_queue, val); _bind(lpred, "time_out",_pool.time_out, val); _bind(lpred, "buffsize", _pool.buffsize, val); _bind(lpred, "socketsize", _pool.socketsize, val); if(lpred[0]=='}') { if(_pool.socketsize && _pool.socketsize < _pool.buffsize) { _pool.socketsize = _pool.buffsize; } if(_pool.min_threads==0) _pool.min_threads=1; if(_pool.max_threads < _pool.min_threads) _pool.max_threads = _pool.min_threads; #ifdef DEBUG _pool.min_threads =1; #endif } } if(_section == "[ssl]") { _bind(lpred, "ssl_lib", _ssl.ssl_lib, val); _bind(lpred, "crypto_lib", _ssl.crypto_lib, val); _bind(lpred, "srv_certificate_file",_ssl.sCert, val); _bind(lpred, "srv_certificate_key_file",_ssl.sPrivKey, val); _bind(lpred, "srv_certificate_chain_file",_ssl.sChain, val); _bind(lpred, "cli_certificate_key_file",_ssl.cPrivKey, val); _bind(lpred, "cli_certificate_file",_ssl.cCert, val); _bind(lpred, "ca_certificate_file",_ssl.sCaCert, val); BIND(_ssl, version); if(lpred[0]=='}') { fix_path(_ssl.sCert); fix_path(_ssl.sPrivKey); fix_path(_ssl.sChain); fix_path(_ssl.sCaCert); fix_path(_ssl.cPrivKey); fix_path(_ssl.cCert); fix_path(_ssl.cCsr); } } } catch(int done) {} }
int main(int argc, char *argv[]) { char *input_filename=NULL; char *output_filename=NULL; BITMAP *bmp=NULL; unsigned char *output_buffer=NULL; FILE *fp; int i; STARTUPINFO si; PROCESS_INFORMATION pi; char path[MAX_PATH]; char args[MAX_PATH * 3]; char temp[MAX_PATH], temp2[MAX_PATH]; RGB pal[256]; char xml_filename[MAX_PATH], png_filename[MAX_PATH]; char *p; font_struct font; char *bmfontgen_filename="BMFontGen.exe"; memset(&font, 0, sizeof(font)); if (argc < 4) { printf ("fontgen [options] [filename].txt -o [filename].bin\n"); goto error; } for (i = 1; i < argc;) { if (strcmp(argv[i], "-2") == 0) { round_up_width = TRUE; i++; } else if (strcmp(argv[i], "-b") == 0) { bmfontgen_filename = argv[i+1]; fix_path(bmfontgen_filename); i += 2; } else if (strcmp (argv[i], "-o") == 0) { output_filename = argv[i+1]; fix_path(output_filename); i += 2; } else { input_filename = argv[i]; fix_path(input_filename); i++; } } if (input_filename == NULL) { printf ("no input filename specified\n"); exit (1); } if (output_filename == NULL) { printf ("no output filename specified\n"); exit (1); } convert_slash(input_filename); convert_slash(output_filename); // Execute BMFontGen GetCurrentDirectoryA(sizeof(temp), temp); if (!PathRelativePathToA(temp2, temp, FILE_ATTRIBUTE_DIRECTORY, bmfontgen_filename, FILE_ATTRIBUTE_NORMAL)) strcpy_s(temp2, sizeof(temp2), bmfontgen_filename); sprintf_s(args, sizeof(args), "%s -optfile ", temp2); if (!PathRelativePathToA(temp2, temp, FILE_ATTRIBUTE_DIRECTORY, input_filename, FILE_ATTRIBUTE_NORMAL)) strcpy_s(temp2, sizeof(temp2), input_filename); strcat_s(args, sizeof(args), temp2); strcpy_s(path, sizeof(path), temp2); if ((p = strrchr(path, '\\')) != NULL) p[1] = '\0'; strcat_s(args, sizeof(args), " -output "); strcat_s(args, sizeof(args), path); strcat_s(args, sizeof(args), "font"); ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); si.wShowWindow = SW_HIDE; si.dwFlags = 0; printf("%s\n", args); if (CreateProcessA(NULL, args, NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE, NULL, NULL, &si, &pi) == 0) { LPVOID lpMsgBuf; DWORD err=GetLastError(); FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language (LPTSTR) &lpMsgBuf, 0, NULL); printf("Error executing BMFontGen: %s\n", lpMsgBuf); LocalFree(lpMsgBuf); exit(1); } printf("Creating font..."); WaitForSingleObject(pi.hProcess, INFINITE); printf("done\n"); // Close process and thread handles. CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); // Load XML file strcpy_s(xml_filename, sizeof(xml_filename), path); strcat_s(xml_filename, sizeof(xml_filename), "font.xml"); read_font_xml(xml_filename, &font); // Start going through XML and copying font to our 12x12 1BPP buffer allegro_init(); loadpng_init(); set_color_depth(8); if (strrchr(font.bitmaps[0].filename, '\\') == NULL) { strcpy_s(png_filename, sizeof(png_filename), input_filename); p = strrchr(png_filename, '\\'); strcpy_s(p+1, sizeof(png_filename)-((p+1)-png_filename), font.bitmaps[0].filename); } else strcpy_s(png_filename, sizeof(png_filename), font.bitmaps[0].filename); if ((bmp = load_bitmap(png_filename, pal)) == NULL) { printf("Error loading generated png file\n"); exit(1); } output_buffer = malloc(12 * 12 / 8 * 1024); if (output_buffer == NULL) { printf("Error allocating buffer\n"); exit(1); } memset(output_buffer, 0, 12 * 12 / 8 * 1024); // Copy glyphs to raw buffer for (i = 0; i < font.num_glyphs; i++) copy_glyph(&font.glyphs[i], bmp, output_buffer); // Write final output if (fopen_s(&fp, output_filename, "wb") != 0) { printf("Error writing output\n"); goto error; } fwrite((void *)output_buffer, 1, 12 * 12 / 8 * 1024, fp); fclose(fp); error: if (bmp) destroy_bitmap(bmp); if (font.bitmaps) free(font.bitmaps); if (font.glyphs) free(font.glyphs); //printf ( "Press any key to continue..." ); //getch(); return 0; }
int do_rm(char *argv[]) { char buf[128], *leaf = argv[0]; sprintf(buf, "%s/%s", cwd, leaf); return hw3_ops.unlink(fix_path(buf)); }