Newer
Older
access-test / modules / src / test_link.c
Nomura Kei on 5 Dec 2022 878 bytes update
/**
 * @file	test_link.c
 * @brief	link テスト
 * @author	Nomura Kei
 * @copyright 2008  Nomura Kei
 */
#include <stdio.h>
#include <errno.h>

#include <unistd.h>

#include <filetype.h>
#include <test_link.h>


/**
 * 指定されたパスのシンボリックリンクを生成します。
 * 指定されたパスが存在しない場合は、errno に ENOENT が設定され、false を返します。
 *
 * @param pathname パス
 * @param linkpath シンボリックリンク先
 * @return true/false (生成成功/生成失敗)
 */
bool can_link(const char* pathname, const char* linkpath)
{
	// パス存在有無確認 (しない場合 NG)
	bool is_error = !is_exists(pathname);
	if (is_error)
	{
		errno = ENOENT;
		return false;
	}

	// シンボリックリンク生成
	int ret = symlink(pathname, linkpath);
	bool is_success = (ret == 0);
	return is_success;
}