示例#1
0
/*
 * static final native String mapLibraryName(String)
 */
_jc_object * _JC_JCNI_ATTR
JCNI_java_lang_VMRuntime_mapLibraryName(_jc_env *env, _jc_object *string)
{
	size_t name_len;
	char *fname;
	char *name;

	/* Check for null */
	if (string == NULL) {
		_jc_post_exception(env, _JC_NullPointerException);
		_jc_throw_exception(env);
	}

	/* Decode string */
	name_len = _jc_decode_string_utf8(env, string, NULL);
	if ((name = _JC_STACK_ALLOC(env, name_len + 1)) == NULL) {
		_jc_post_exception_info(env);
		_jc_throw_exception(env);
	}
	_jc_decode_string_utf8(env, string, name);

	/* Format filename */
	if ((fname = _JC_FORMAT_STRING(env, _JC_LIBRARY_FMT, name)) == NULL) {
		_jc_post_exception_info(env);
		_jc_throw_exception(env);
	}

	/* Create new String object */
	if ((string = _jc_new_string(env, fname, strlen(fname))) == NULL)
		_jc_throw_exception(env);

	/* Done */
	return string;
}
示例#2
0
文件: misc.c 项目: archiecobbs/jcvm
/*
 * Create a subdirectory under 'root' if it doesn't already exist.
 * The pathname is the name of any file in the subdirectory.
 */
jint
_jc_create_subdir(_jc_env *env, const char *root, const char *pathname)
{
	const size_t rlen = strlen(root);
	const char *error_path;
	struct stat info;
	char *next;
	char *buf;
	char *s;

	/* The root directory must exist */
	error_path = root;
	if (stat(root, &info) == -1)
		goto io_err;
	if ((info.st_mode & S_IFMT) != S_IFDIR) {
		errno = ENOTDIR;
		goto io_err;
	}

	/* Check successive subdirectories */
	if ((buf = _JC_FORMAT_STRING(env, "%s%s%s",
	    root, _JC_FILE_SEPARATOR, pathname)) == NULL) {
		_jc_post_exception_info(env);
		return JNI_ERR;
	}
	error_path = buf;
	for (s = buf + rlen + 1; ; s = next) {

		/* Another directory in path? If not, we're done */
		if ((next = strstr(s, _JC_FILE_SEPARATOR)) == NULL)
			return JNI_OK;

		/* Check directory status; create if not found */
		*next = '\0';
		if (stat(buf, &info) == -1) {
			if (errno != ENOENT)
				goto io_err;
			if (mkdir(buf, 0755) == -1)
				goto io_err;
		} else if ((info.st_mode & S_IFMT) != S_IFDIR) {
			errno = ENOTDIR;
			goto io_err;
		}
		strcpy(next, _JC_FILE_SEPARATOR);
		next += strlen(_JC_FILE_SEPARATOR);
	}

io_err:
	/* Failed; throw an error */
	_jc_post_exception_msg(env, _JC_InternalError,
	    "%s: %s", error_path, strerror(errno));
	return JNI_ERR;
}