コード例 #1
0
bool test_file_writer_write_args_system_call (Test *test)
{
        FileWriter *writer;
        FILE *file_readonly, *file_swap;
        char *path;

        TITLE ();
        CATCH (!(file_readonly = fopen ("stage/file_writer/file", "r")));
        CATCH (!(path = directory_current_path ()));
        CATCH (!string_append (&path, "/stage/file_writer/args"));
        if (file_exists (path)) {
                CATCH (!file_remove (path));
        }
        CATCH (!(writer = file_writer_create (path, FileWriterModeTruncate)));
        file_swap = writer->file;
        writer->file = file_readonly;
        CATCH (file_writer_write_args (writer, "%s", "test"));
        CATCH (error_count () == 0);
        CATCH (error_at (0).error != ErrorSystemCall);
        writer->file = file_swap;
        fclose (file_readonly);
        file_writer_destroy (writer);
        string_destroy (path);
        PASS ();
}
コード例 #2
0
ファイル: points.cpp プロジェクト: ChunHungLiu/GtkRadiant
void Pointfile_Delete (void)
{
  const char* mapname = Map_Name(g_map);
  StringOutputStream name(256);
  name << StringRange(mapname, path_get_filename_base_end(mapname)) << ".lin";
	file_remove(name.c_str());
}
コード例 #3
0
ファイル: preferences.cpp プロジェクト: clbr/netradiant
void CGameDialog::Reset()
{
  if (!g_Preferences.m_global_rc_path)
    InitGlobalPrefPath();
  StringOutputStream strGlobalPref(256);
  strGlobalPref << g_Preferences.m_global_rc_path->str << "global.pref";
  file_remove(strGlobalPref.c_str());
}
コード例 #4
0
ファイル: gcmon.c プロジェクト: asiainfo/gcmon_lib
/*!
*@brief        jvmti的Agent_OnUnload接口的实现,用于清理gcmon资源
*@author       zhaohm3
*@param[in]    vm
*@retval
*@note
*
*@since    2014-9-15 18:08
*@attention
*
*/
JNIEXPORT void JNICALL Agent_OnUnload(JavaVM *vm)
{
    GCMON_PRINT_FUNC();
    JVMClearJvmtiEnv();
    gcmon_thread_exit();
    rbtree_free(gpPerfTree);
    gcmon_souter_free();
    file_close_all();

    if (!gbOOMEvent)
    {
        file_remove(file_get_fsname());
        file_remove(file_get_frname());
    }

    args_free_agentargs();
}
コード例 #5
0
int main(void) {
  const char *s = "$HOME/.config";

  if(file_remove(s) == 1) {
    return EXIT_SUCCESS;
  } else {
    return EXIT_FAILURE;
  }
}
コード例 #6
0
ファイル: hookers.c プロジェクト: ScriptBasic/ScriptBasic
/*FUNCTION*/
int hook_remove(pExecuteObject pEo,
                char *pszFileName
  ){
/*noverbatim
CUT*/
  int iAccessPermission = HOOK_FILE_ACCESS(pszFileName);
  if( !(iAccessPermission&1) )return -1;

  return file_remove(pszFileName);
  }
コード例 #7
0
bool test_file_remove (Test *test)
{
	char *path;
	FILE *file;

	TITLE ();
	CATCH (file_remove (NULL));
	CATCH (file_remove ("badpathformat"));
	CATCH (!(path = directory_current_path ()));
	CATCH (!string_append (&path, "/stage/remove/file"));
        /* d stage/remove */
	if (!file_exists (path)) {
		CATCH (!(file = fopen (path, "ab+")));
		fclose (file);
	}
	CATCH (!file_remove (path));
	CATCH (file_exists (path));
	string_destroy (path);
	PASS ();
}
コード例 #8
0
ファイル: preferences.cpp プロジェクト: Triang3l/netradiant
bool Preferences_Save_Safe( PreferenceDictionary& preferences, const char* filename ){
	Array<char> tmpName( filename, filename + strlen( filename ) + 1 + 3 );
	*( tmpName.end() - 4 ) = 'T';
	*( tmpName.end() - 3 ) = 'M';
	*( tmpName.end() - 2 ) = 'P';
	*( tmpName.end() - 1 ) = '\0';

	return Preferences_Save( preferences, tmpName.data() )
		   && ( !file_exists( filename ) || file_remove( filename ) )
		   && file_move( tmpName.data(), filename );
}
コード例 #9
0
ファイル: referencecache.cpp プロジェクト: kevlund/ufoai
static bool file_saveBackup (const std::string& path)
{
    if (file_writeable(path)) {
        std::string backup = os::stripExtension(path) + ".bak";

        return (!file_exists(backup) || file_remove(backup)) // remove backup
               && file_move(path, backup); // rename current to backup
    }

    globalErrorStream() << "ERROR: map path is not writeable: " << path << "\n";
    return false;
}
コード例 #10
0
static int
file_close_remove(struct rtems_bsd_program_control *prog_ctrl, FILE *file)
{
	int rv = EOF;

	rv = file_remove(prog_ctrl, file);
	if (rv == 0) {
		rv = fclose(file);
	}

	return rv;
}
コード例 #11
0
ファイル: serv.c プロジェクト: BGCX262/zt-jos-svn-to-git
void
serve_remove(u_int envid, struct Fsreq_remove *rq)
{
    int r = 0;
    u_char path[MAXPATHLEN];    
	if (debug) printf("serve_remove %08x %s\n", envid, rq->req_path);
    memcpy(path, rq->req_path, MAXPATHLEN);
    r = file_remove(path);
    ipc_send(envid, r, 0, 0);
    
	// Your code here
	//panic("serve_remove not implemented");
}
コード例 #12
0
ファイル: sw_syslibc.c プロジェクト: billzbh/ov-secure-kernel
/**
 * @brief 
 * f_remove - Deletes the file whose name is specified in filename
 *
 * @param rm_p - string containing the name of the file to be deleted
 *
 * @return - if the file is successfully deleted, a zero value is returned.
 *           On failure, a non-zero value is returned
 */
int f_remove(const char *rm_p)
{
#ifdef CONFIG_FILESYSTEM_SUPPORT
    int r_m;
    r_m=file_remove(rm_p);
    if(r_m==-1) {
        return -1;
    }
    return 0;
#else
    return -1;
#endif

}
コード例 #13
0
ファイル: referencecache.cpp プロジェクト: clbr/netradiant
bool file_saveBackup(const char* path)
{
  if(file_writeable(path))
  {
	  StringOutputStream backup(256);
    backup << StringRange(path, path_get_extension(path)) << "bak";

    return (!file_exists(backup.c_str()) || file_remove(backup.c_str())) // remove backup
      && file_move(path, backup.c_str()); // rename current to backup
  }

  globalErrorStream() << "map path is not writeable: " << makeQuoted(path) << "\n";
  return false;
}
コード例 #14
0
ファイル: serv.c プロジェクト: yaobaiwei/JOS
void
serve_remove(envid_t envid, struct Fsreq_remove *rq)
{
	char path[MAXPATHLEN];
	int r;

	if (debug)
		cprintf("serve_remove %08x %s\n", envid, rq->req_path);

	// Copy in the path, making sure it's null-terminated
	memmove(path, rq->req_path, MAXPATHLEN);
	path[MAXPATHLEN-1] = 0;

	// Delete the specified file
	r = file_remove(path);
	ipc_send(envid, r, 0, 0);
}
コード例 #15
0
bool test_print_log_begin_invalid_operation (Test *test)
{
        char *path;

        TITLE ();
        CATCH (!(path = directory_current_path ()));
        CATCH (!string_append (&path, "/stage/print_log/log"));
        if (file_exists (path)) {
                CATCH (!file_remove (path));
        }
        CATCH (!print_log_begin (path));
        CATCH (print_log_begin (path));
        CATCH (error_count () == 0);
        CATCH (error_at (0).error != ErrorInvalidOperation);
        CATCH (!print_log_end ());
        string_destroy (path);
        PASS ();
}
コード例 #16
0
ファイル: Desktop.cpp プロジェクト: GustavoMOG/ede
bool Desktop::remove_icon(DesktopIcon *di, bool real_delete) {
	bool ret = true;

	if(real_delete) {
		if(di->get_icon_type() == DESKTOP_ICON_TYPE_FOLDER) {
			if(!dir_empty(di->get_path())) {
				alert(_("This folder is not empty. Recursive removal of not empty folders is not yet supported"));
				return false;
			}
			ret = dir_remove(di->get_path());
		} else {
			ret = file_remove(di->get_path());
		}
	}

	remove(di);
	redraw();
	return ret;
}
コード例 #17
0
ファイル: serv.c プロジェクト: stone-SJH/joslabs-byStone
// Remove the file req->req_path.
int
serve_remove(envid_t envid, struct Fsreq_remove *req)
{
	char path[MAXPATHLEN];
	int r;

	if (debug)
		cprintf("serve_remove %08x %s\n", envid, req->req_path);

	// Delete the named file.
	// Note: This request doesn't refer to an open file.

	// Copy in the path, making sure it's null-terminated
	memmove(path, req->req_path, MAXPATHLEN);
	path[MAXPATHLEN-1] = 0;

	// Delete the specified file
	return file_remove(path);
}
コード例 #18
0
ファイル: test-file.c プロジェクト: xinoir/dizzy
static int test_file_remove() {
    int e;
    FILE *file;
    char filename[] = "/tmp/test-file-XXXXXXXX";

    e = mkstemp(filename); 
    e = file_create(filename, &file);
    assert(e == 0);
    assert(file);

    fclose(file);

    e = file_remove(filename);
    assert(e == 0);

    e = file_exists(filename);
    assert(e == 0);

    return 0;
}
コード例 #19
0
bool test_file_writer_write_args_invalid_argument_2 (Test *test)
{
        FileWriter *writer;
        char *path;

        TITLE ();
        CATCH (!(path = directory_current_path ()));
        CATCH (!string_append (&path, "/stage/file_writer/args"));
        if (file_exists (path)) {
                CATCH (!file_remove (path));
        }
        CATCH (!(writer = file_writer_create (path, FileWriterModeTruncate)));
        CATCH (file_writer_write_args (writer, NULL, "test"));
        CATCH (error_count () == 0);
        CATCH (error_at (0).error != ErrorInvalidArgument);
        CATCH (error_at (0).code != 2);
        file_writer_destroy (writer);
        string_destroy (path);
        PASS ();
}
コード例 #20
0
bool test_file_writer_write_args (Test *test)
{
        FileWriter *writer;
        FileReader *reader;
        char *path;

        TITLE ();
        CATCH (!(path = directory_current_path ()));
        CATCH (!string_append (&path, "/stage/file_writer/args"));
        if (file_exists (path)) {
                CATCH (!file_remove (path));
        }
        CATCH (!(writer = file_writer_create (path, FileWriterModeTruncate)));
        CATCH (!file_writer_write_args (writer, "abc%i123%s", 0, "4"));
        file_writer_destroy (writer);
        CATCH (!(reader = file_reader_create (path)));
        CATCH (!string_equals ((const char *)reader->map, "abc01234"));
        file_reader_destroy (reader);
        string_destroy (path);
        PASS ();
}
コード例 #21
0
bool test_print_log_2 (Test *test)
{
        FileReader *reader;
        char *path;

        TITLE ();
        CATCH (!(path = directory_current_path ()));
        CATCH (!string_append (&path, "/stage/print_log/log"));
        print_silent (false);
        if (file_exists (path)) {
                CATCH (!file_remove (path));
        }
        CATCH (!print_log_begin (path));
        CATCH (!print (" \b"));
        CATCH (!print_log_end ());
        CATCH (!(reader = file_reader_create (path)));
        print_silent (true);
        CATCH (!string_equals ((const char *)reader->map, " \b"));
        file_reader_destroy (reader);
        string_destroy (path);
        PASS ();
}
コード例 #22
0
ファイル: serv.c プロジェクト: SivilTaram/Jos-mips
void
serve_remove(u_int envid, struct Fsreq_remove *rq)
{
	if (debug) {
		writef("serve_map %08x %s\n", envid, rq->req_path);
	}

	// Your code here
	int r;
	u_char path[MAXPATHLEN];

	// Copy in the path, making sure it's null-terminated
	user_bcopy(rq->req_path, path, MAXPATHLEN);
	path[MAXPATHLEN - 1] = 0;

	if ((r = file_remove((char *)path)) < 0) {
		ipc_send(envid, r, 0, 0);
		return;
	}

	ipc_send(envid, 0, 0, 0);//PTE_V);
	//	user_panic("serve_remove not implemented");
}
コード例 #23
0
ファイル: io.c プロジェクト: atikinn/EOS
int kremove(const char *path) {
    if (is_dev(path)) return -1; /* devices can be only opened right now */
    return file_remove(cwd, path);
}
コード例 #24
0
int
udf_cask_smd_accept_fn(char *module, as_smd_item_list_t *items, void *udata, uint32_t accept_opt)
{
	if (accept_opt & AS_SMD_ACCEPT_OPT_CREATE) {
		cf_debug(AS_UDF, "(doing nothing in UDF accept cb for module creation)");
		return 0;
	}

	cf_debug(AS_UDF, "UDF CASK accept fn : n items %d", items->num_items);

	// For each item in the list, see if the current version
	// is different from the curretly stored version
	// and if the new item is new, write to the storage directory
	for (int i = 0; i < items->num_items ; i++) {

		as_smd_item_t *item = items->item[i];

		if (item->action == AS_SMD_ACTION_SET) {

			json_error_t json_err;
			json_t *item_obj = json_loads(item->value, 0 /*flags*/, &json_err);

			/*item->key is name */
			json_t *content64_obj = json_object_get(item_obj, "content64");
			const char *content64_str = json_string_value(content64_obj);

			// base 64 decode it
			int content_len = strlen(content64_str);
			char *content_str = cf_malloc(content_len);
			// base64_decode function does not add '\0' at the end , if input string is of length%3 = 0
			// content_len is greater than required size.
			// It leads adding junk characters at the end of LUA file.
			// Zeroing out the string, so that it will have '\0' at end in all cases.
			memset (content_str, 0, content_len);

			int e = base64_decode((uint8_t *)content64_str, (uint8_t *)content_str, &content_len, true);
			if (e) {
				cf_info(AS_UDF, "invalid script on accept, will not register %s", item->key);
				cf_free(content_str);
				json_decref(content64_obj);
				json_decref(item_obj);
				continue;
			}

			cf_debug(AS_UDF, "pushing to %s, %d bytes [%s]", item->key, content_len, content_str);
			mod_lua_wrlock(&mod_lua);

			// content_gen is actually a hash. Not sure if it's filled out or what.
			unsigned char       content_gen[256]    = {0};
			e = file_write(item->key, (uint8_t *) content_str, content_len, content_gen);
			cf_free(content_str);
			json_decref(content64_obj);
			json_decref(item_obj);
			if ( e ) {
				mod_lua_unlock(&mod_lua);
				cf_info(AS_UDF, "invalid script on accept, will not register %s", item->key);
				continue;
			}
			// Update the cache
			as_module_event ame = {
				.type           = AS_MODULE_EVENT_FILE_ADD,
				.data.filename  = item->key
			};
			as_module_update(&mod_lua, &ame);
			mod_lua_unlock(&mod_lua);
		}
		else if (item->action == AS_SMD_ACTION_DELETE) {
			cf_debug(AS_UDF, "received DELETE SMD action %d key %s", item->action, item->key);

			mod_lua_wrlock(&mod_lua);
			file_remove(item->key);

			// fixes potential cache issues
			as_module_event e = {
				.type           = AS_MODULE_EVENT_FILE_REMOVE,
				.data.filename  = item->key
			};
			as_module_update(&mod_lua, &e);

			mod_lua_unlock(&mod_lua);

		}
		else {
コード例 #25
0
ファイル: GdbOutput.cpp プロジェクト: edeproject/ede
bool gdb_output_generate(const char *path, TempFile &t, int pid) {
	E_RETURN_VAL_IF_FAIL(path != NULL, false);

	int      tfd = -1;
	TempFile scr;

	if(!scr.create("/tmp/.ecrash-script")) {
		E_WARNING(E_STRLOC ": Unable to create temporary file for debugger script: (%i) %s",
				scr.status(), strerror(scr.status()));
		return false;
	}

	if(!t.create("/tmp/.ecrash-output")) {
		E_WARNING(E_STRLOC ": Unable to create temporary file for debugger output: (%i) %s",
				t.status(), strerror(t.status()));
		return false;
	}

	tfd = t.handle();

	/* write script */
	::write(scr.handle(), "bt\nquit\n", 8);
	scr.set_auto_delete(true);
	scr.close();

	String gdb_path = file_path("gdb");
	if(gdb_path.empty()) {
		/* write straight to the file, so dialog could show it */
		write_str(tfd, "Unable to find gdb. Please install it first");

		/* see it as valid, so dialog could be shown */
		return true;
	}

	/*
	 * to find core file, we will try these strategies: first try to open 'core.PID' if
	 * we got PID (default on linux); if does not exists, try to open 'core'; everything is
	 * assumed current folder, whatever it was set
	 */
	bool   core_found = false;
	String core_path;
	if(pid > -1) {
		core_path.printf("%s.%i", CORE_FILE, pid);
		if(file_test(core_path.c_str(), FILE_TEST_IS_REGULAR))
			core_found = true;
	}

	if(!core_found) {
		core_path = CORE_FILE;
		if(file_test(core_path.c_str(), FILE_TEST_IS_REGULAR))
			core_found = true;
	}

	if(!core_found) {
		write_str(tfd, "Unable to find core file. Backtrace will not be done.");
		/* see it as valid, so dialog could be shown */
		return true;
	}

	pid_t gdb_pid = fork();

    if(gdb_pid == -1) {
		E_WARNING(E_STRLOC ": Unable to fork the process\n");
        return false;
    } else if(gdb_pid == 0) {
		/* child; redirect to the file */
        dup2(tfd, 1);
		t.close();

		::write(1, " ", 1);

        char* argv[8];
        argv[0] = (char*)gdb_path.c_str();
        argv[1] = (char*)"--quiet";
        argv[2] = (char*)"--batch";
        argv[3] = (char*)"-x";
        argv[4] = (char*)scr.name();
        argv[5] = (char*)path;
        argv[6] = (char*)core_path.c_str();
        argv[7] = 0;

        execvp(argv[0], argv);
        return false;
    } else {
        int status;

        if(waitpid(gdb_pid, &status, 0) != gdb_pid) {
			E_WARNING(E_STRLOC ": Failed to execute waitpid() properly\n");
            return false;
		}
    }

	file_remove(core_path.c_str());
	return true;
}
コード例 #26
0
ファイル: syscall.c プロジェクト: Swelo0/prog_sys_le_retour
// System call handler: call the appropriate system call according to the nb argument.
// Called by the assembly code _syscall_handler
int syscall_handler(syscall_t nb, uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4, uint32_t caller_tss_selector) {
	
	printf("task %d called syscall_handler\n", caller_tss_selector);
	
	// Offset for pointers to reach the real address (task thinks it indexes since 0x0 but it really doesn't)
	task_t* t = get_task(caller_tss_selector);
	uint32_t offset = FIRST_TASK + t.gdt_tss_sel * TASK_LIMIT;
	
	int ret = 0;
	switch (nb) {
		
		case SYSCALL_PUTC:
			UNUSED(arg2);
			UNUSED(arg3);
			UNUSED(arg4);
			print_char((char) arg1 + offset);
			break;
			
		case SYSCALL_PUTS:
			UNUSED(arg2);
			UNUSED(arg3);
			UNUSED(arg4);
			print_str((char*) arg1 + offset);
			break;
			
		case SYSCALL_EXEC:
			UNUSED(arg2);
			UNUSED(arg3);
			UNUSED(arg4);
			ret = exec((char*) arg1 + offset);
			break;
			
		case SYSCALL_GETC:
			UNUSED(arg1);
			UNUSED(arg2);
			UNUSED(arg3);
			UNUSED(arg4);
			ret = getc();
			break;
			
		case SYSCALL_FILE_STAT:
			UNUSED(arg3);
			UNUSED(arg4);
			ret = file_stat((char*) arg1 + offset, (stat_t*) arg2 + offset);
			break;
			
		case SYSCALL_FILE_READ:
			UNUSED(arg3);
			UNUSED(arg4);
			ret = file_read((char*) arg1 + offset, (void*) arg2 + offset);
			break;
			
		case SYSCALL_FILE_REMOVE:
			UNUSED(arg2);
			UNUSED(arg3);
			UNUSED(arg4);
			ret = file_remove((char*) arg1 + offset);
			break;
			
		case SYSCALL_FILE_ITERATOR:
			UNUSED(arg2);
			UNUSED(arg3);
			UNUSED(arg4);
			file_iterator_t it = file_iterator();
			arg1 = (uint32_t) &it + offset;
			break;
			
		case SYSCALL_FILE_NEXT:
			UNUSED(arg3);
			UNUSED(arg4);
			ret = file_next((char*) arg1 + offset, (file_iterator_t*) arg2 + offset);
			break;
			
		case SYSCALL_GET_TICKS:
			UNUSED(arg1);
			UNUSED(arg2);
			UNUSED(arg3);
			UNUSED(arg4);
			ret = get_ticks();
			break;
			
		default:
			UNUSED(nb);
			UNUSED(arg1);
			UNUSED(arg2);
			UNUSED(arg3);
			UNUSED(arg4);
			break;
		
	}
	
	// End of routine
	return ret;
	
}
コード例 #27
0
ファイル: mod_file.c プロジェクト: segafan/bennugd-monolithic
static int modfile_remove( INSTANCE * my, int * params )
{
    int r = file_remove( string_get( params[0] ) ) ;
    string_discard( params[0] ) ;
    return r ;
}
コード例 #28
0
ファイル: udf_cask.c プロジェクト: CowLeo/aerospike-server
int
udf_cask_smd_accept_fn(char *module, as_smd_item_list_t *items, void *udata, uint32_t accept_opt)
{
	if (accept_opt & AS_SMD_ACCEPT_OPT_CREATE) {
		cf_debug(AS_UDF, "(doing nothing in UDF accept cb for module creation)");
		return 0;
	}

	cf_debug(AS_UDF, "UDF CASK accept fn : n items %zu", items->num_items);

	// For each item in the list, see if the current version
	// is different from the curretly stored version
	// and if the new item is new, write to the storage directory
	for (int i = 0; i < items->num_items ; i++) {

		as_smd_item_t *item = items->item[i];

		if (item->action == AS_SMD_ACTION_SET) {

			json_error_t json_err;
			json_t *item_obj = json_loads(item->value, 0 /*flags*/, &json_err);

			/*item->key is name */
			json_t *content64_obj = json_object_get(item_obj, "content64");
			const char *content64_str = json_string_value(content64_obj);

			// base 64 decode it
			uint32_t encoded_len = strlen(content64_str);
			uint32_t decoded_len = cf_b64_decoded_buf_size(encoded_len) + 1;
			char *content_str = cf_malloc(decoded_len);

			if (! cf_b64_validate_and_decode(content64_str, encoded_len, (uint8_t*)content_str, &decoded_len)) {
				cf_info(AS_UDF, "invalid script on accept, will not register %s", item->key);
				cf_free(content_str);
				json_decref(content64_obj);
				json_decref(item_obj);
				continue;
			}

			content_str[decoded_len] = 0;

			cf_debug(AS_UDF, "pushing to %s, %d bytes [%s]", item->key, decoded_len, content_str);
			mod_lua_wrlock(&mod_lua);

			// content_gen is actually a hash. Not sure if it's filled out or what.
			unsigned char       content_gen[256]    = {0};
			int e = file_write(item->key, (uint8_t *) content_str, decoded_len, content_gen);
			cf_free(content_str);
			json_decref(content64_obj);
			json_decref(item_obj);
			if ( e ) {
				mod_lua_unlock(&mod_lua);
				cf_info(AS_UDF, "invalid script on accept, will not register %s", item->key);
				continue;
			}
			// Update the cache
			as_module_event ame = {
				.type           = AS_MODULE_EVENT_FILE_ADD,
				.data.filename  = item->key
			};
			as_module_update(&mod_lua, &ame);
			mod_lua_unlock(&mod_lua);
		}
		else if (item->action == AS_SMD_ACTION_DELETE) {
			cf_debug(AS_UDF, "received DELETE SMD action %d key %s", item->action, item->key);

			mod_lua_wrlock(&mod_lua);
			file_remove(item->key);

			// fixes potential cache issues
			as_module_event e = {
				.type           = AS_MODULE_EVENT_FILE_REMOVE,
				.data.filename  = item->key
			};
			as_module_update(&mod_lua, &e);

			mod_lua_unlock(&mod_lua);

		}
		else {