コード例 #1
0
ファイル: util.c プロジェクト: phschoen/tig
const char *
mkdate(const struct time *time, enum date date, bool local, const char *custom_format)
{
	static char buf[SIZEOF_STR];
	struct tm tm;
	const char *format;

	if (!date || !time || !time->sec)
		return "";

	if (date == DATE_RELATIVE || date == DATE_RELATIVE_COMPACT)
		return get_relative_date(time, buf, sizeof(buf),
					 date == DATE_RELATIVE_COMPACT);

	if (local) {
		time_t date = time->sec + time->tz;
		localtime_r(&date, &tm);
	}
	else {
		gmtime_r(&time->sec, &tm);
	}

	format = date != DATE_CUSTOM
	       ? "%Y-%m-%d %H:%M"
	       : custom_format ? custom_format : "%Y-%m-%d";
	return strftime(buf, sizeof(buf), format, &tm) ? buf : NULL;
}
コード例 #2
0
ファイル: util.c プロジェクト: ChunHungLiu/tig
const char *
mkdate(const struct time *time, enum date date)
{
	static char buf[STRING_SIZE("2006-04-29 14:21") + 1];
	struct tm tm;
	const char *format;

	if (!date || !time || !time->sec)
		return "";

	if (date == DATE_RELATIVE)
		return get_relative_date(time, buf, sizeof(buf));

	if (date == DATE_LOCAL) {
		time_t date = time->sec + time->tz;
		localtime_r(&date, &tm);
	}
	else {
		gmtime_r(&time->sec, &tm);
	}

	format = date == DATE_SHORT ? "%Y-%m-%d" : "%Y-%m-%d %H:%M";
	return strftime(buf, sizeof(buf), format, &tm) ? buf : NULL;
}
コード例 #3
0
ファイル: set_fileattr.c プロジェクト: hyakki-/sgi
int
main(
    int	argc,
    char	**argv)
{
    dm_sessid_t	sid = DM_NO_SESSION;
    void		*hanp;
    size_t		hlen;
    dm_fileattr_t	fileattr;
    u_int		mask = 0;
    char		*pathname;
    char		*name;
    int		opt;

    if (Progname = strrchr(argv[0], '/')) {
        Progname++;
    } else {
        Progname = argv[0];
    }

    opterr = 0;
    while ((opt = getopt(argc, argv, "M:u:g:a:m:c:d:S:s:")) != EOF) {
        switch (opt) {
        case 'M':
            mask |= DM_AT_MODE;
            fileattr.fa_mode = strtol (optarg, NULL, 8);
            break;
        case 'u':
            mask |= DM_AT_UID;
            fileattr.fa_uid = atol(optarg);
            break;
        case 'g':
            mask |= DM_AT_GID;
            fileattr.fa_gid = atol(optarg);
            break;
        case 'a':
            mask |= DM_AT_ATIME;
            if (get_absolute_date(optarg, &fileattr.FA_ATIME))
                break;
            if (get_relative_date(optarg, &fileattr.FA_ATIME))
                break;
            usage();
        case 'm':
            mask |= DM_AT_MTIME;
            if (get_absolute_date(optarg, &fileattr.FA_MTIME))
                break;
            if (get_relative_date(optarg, &fileattr.FA_MTIME))
                break;
            usage();
        case 'c':
            mask |= DM_AT_CTIME;
            if (get_absolute_date(optarg, &fileattr.FA_CTIME))
                break;
            if (get_relative_date(optarg, &fileattr.FA_CTIME))
                break;
            usage();
        case 'd':
            mask |= DM_AT_DTIME;
            if (get_absolute_date(optarg, &fileattr.FA_DTIME))
                break;
            if (get_relative_date(optarg, &fileattr.FA_DTIME))
                break;
            usage();
        case 'S':
            mask |= DM_AT_SIZE;
            fileattr.fa_size = atol(optarg);
            break;
        case 's':
            sid = atol(optarg);
            break;
        case '?':
            usage();
        }
    }
    if (optind + 1 != argc) {
        usage();
    }
    pathname = argv[optind];

    if (dm_init_service(&name) == -1)  {
        fprintf(stderr, "Can't inititalize the DMAPI\n");
        exit(1);
    }
    if (sid == DM_NO_SESSION)
        find_test_session(&sid);

    if (dm_path_to_handle(pathname, &hanp, &hlen)) {
        fprintf(stderr, "dm_path_to_handle failed, %s\n",
                strerror(errno));
        exit(1);
    }

    if (dm_set_fileattr(sid, hanp, hlen, DM_NO_TOKEN, mask, &fileattr)) {
        fprintf(stderr, "dm_set_fileattr failed, %s\n",
                strerror(errno));
        exit(1);
    }
    exit(0);
}