- 01
 - 02
 - 03
 - 04
 - 05
 - 06
 - 07
 - 08
 - 09
 - 10
 - 11
 - 12
 - 13
 - 14
 - 15
 - 16
 - 17
 - 18
 - 19
 - 20
 - 21
 - 22
 - 23
 - 24
 - 25
 - 26
 - 27
 - 28
 - 29
 - 30
 - 31
 - 32
 - 33
 - 34
 - 35
 - 36
 - 37
 - 38
 - 39
 - 40
 - 41
 - 42
 - 43
 - 44
 - 45
 - 46
 - 47
 - 48
 - 49
 - 50
 - 51
 - 52
 - 53
 - 54
 - 55
 - 56
 - 57
 - 58
 - 59
 - 60
 - 61
 - 62
 - 63
 - 64
 - 65
 - 66
 - 67
 - 68
 - 69
 - 70
 - 71
 - 72
 - 73
 - 74
 - 75
 - 76
 - 77
 - 78
 - 79
 - 80
 - 81
 - 82
 - 83
 - 84
 - 85
 
                        /*Checks whether the path exists and the path is directory, otherwise creates a new directory*/
RET_VALS check_create_directory(const char* const dir_path, void (*print_func)(int, char *,...))
{
	RET_VALS ret_val;
	struct stat sb;
	ret_val = RET_OK;
	if (NULL != dir_path)
	{
		if(NULL != print_func)
		{
			print_func(DBG_INFO, "%s - Checking %s existence\n", __FUNCTION__, dir_path);
		}
		else
		{
			dbgprintln("Checking %s existence", dir_path);
		}
		if (0 != stat(dir_path, &sb) || (false == S_ISDIR(sb.st_mode)))
		{
			ret_val |= RET_DIR_MISSING;
			if(NULL != print_func)
			{
				print_func(DBG_INFO, "%s - %s is missing\n", __FUNCTION__, dir_path);
			}
			else
			{
				dbgprintln("%s is missing", dir_path);
			}
			errno = 0;
			if (0 == mkdir(dir_path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH))
			{
				ret_val |= RET_DIR_CREATE_OK;
				if(NULL != print_func)
				{
					print_func(DBG_INFO, "%s - %s is successfully created\n", __FUNCTION__, dir_path);
				}
				else
				{
					dbgprintln("%s is successfully created", dir_path);
				}
			}
			else
			{
				char err_msg[_K];
				sprintf(err_msg, "Failed to create %s, error %04d - %s", dir_path, errno, strerror(errno));
				ret_val |= RET_DIR_CREATE_FAILED;
				//dbg_ffln(DBG_ERROR, "Failed to create %s", dir_path);
				if(NULL != print_func)
				{
					print_func(DBG_INFO, "%s - %s\n", __FUNCTION__, err_msg);
				}
				else
				{
					dbgprintln("%s", err_msg);
				}
			}
		}
		else
		{
			ret_val |= RET_DIR_ALREADY_EXIST;
			if(NULL != print_func)
			{
				print_func(DBG_INFO, "%s - %s already exists\n", __FUNCTION__, dir_path);
			}
			else
			{
				dbgprintln("%s already exists", dir_path);
			}
		}
	}
	else
	{
		ret_val = RET_DIR_MISSING;
		if(NULL != print_func)
		{
			print_func(DBG_ERROR, "%s - No directory name is provided", __FUNCTION__);
		}
		else
		{
			dbgprintln("No directory name is provided");
		}
	}
	return ret_val;
}
                                     
        
            Продолжаем раскопки. Вообще весь .с файл можно сюда выложить.