Пример #1
0
void main()
  {
    FILE *tf1, *tf2;

    tf1 = fopen( make_temp_name(), "w" );
    tf2 = fopen( make_temp_name(), "w" );
    fputs( "temp file 1", tf1 );
    fputs( "temp file 2", tf2 );
    fclose( tf1 );
    fclose( tf2 );
  }
Пример #2
0
// get new temp
temp_var * new_temp(ast_node root) {
    if (!root)
        return NULL;

    // get root's scope table temp list
    temp_list * t_list = ((symhashtable_t *)root->scope_table)->t_list;

    // get a new temp from the list
    temp_var * new_var = (temp_var *)calloc(1,sizeof(temp_var));
    assert(new_var);

    // give unique id
    new_var->id = t_list->count;

    // make new name -- not yet
    char * name = make_temp_name(new_var->id);

    // put new temp in list
    t_list->list[t_list->count] = new_var;

    // if list is full, expand!
    t_list->count++;
    if (t_list->count == t_list->size) {
        t_list->size *= 2;
        t_list->list = realloc(t_list->list, t_list->size * sizeof(temp_var *));
        assert(t_list->list);
    }

    // add that new temp to local table under the name
    symnode_t * new_node = insert_into_symhashtable(root->scope_table,name, NULL);

    // attach temp to created symnode
    new_var->temp_symnode = new_node;

    // set node type
    set_node_type(new_node, VAR_SYM);

    // set node characteristics
    var_symbol node_model;
    node_model.name = name;
    node_model.type = INT_TS;
    node_model.modifier = SINGLE_DT;
    node_model.specie = TEMP_VAR;
    node_model.byte_size = TYPE_SIZE(INT_TS);

    // save to symbol table
    set_node_var(new_node, &node_model);

    // return newly created temp
    return new_var;
}
Пример #3
0
static time_t
get_boot_time (void)
{
#if defined (BOOT_TIME)
    int counter;
#endif

    if (boot_time_initialized)
        return boot_time;
    boot_time_initialized = 1;

#if defined (CTL_KERN) && defined (KERN_BOOTTIME)
    {
        int mib[2];
        size_t size;
        struct timeval boottime_val;

        mib[0] = CTL_KERN;
        mib[1] = KERN_BOOTTIME;
        size = sizeof (boottime_val);

        if (sysctl (mib, 2, &boottime_val, &size, NULL, 0) >= 0)
        {
            boot_time = boottime_val.tv_sec;
            return boot_time;
        }
    }
#endif /* defined (CTL_KERN) && defined (KERN_BOOTTIME) */

    if (BOOT_TIME_FILE)
    {
        struct stat st;
        if (stat (BOOT_TIME_FILE, &st) == 0)
        {
            boot_time = st.st_mtime;
            return boot_time;
        }
    }

#if defined (BOOT_TIME)
#ifndef CANNOT_DUMP
    /* The utmp routines maintain static state.
       Don't touch that state unless we are initialized,
       since it might not survive dumping.  */
    if (! initialized)
        return boot_time;
#endif /* not CANNOT_DUMP */

    /* Try to get boot time from utmp before wtmp,
       since utmp is typically much smaller than wtmp.
       Passing a null pointer causes get_boot_time_1
       to inspect the default file, namely utmp.  */
    get_boot_time_1 (0, 0);
    if (boot_time)
        return boot_time;

    /* Try to get boot time from the current wtmp file.  */
    get_boot_time_1 (WTMP_FILE, 1);

    /* If we did not find a boot time in wtmp, look at wtmp, and so on.  */
    for (counter = 0; counter < 20 && ! boot_time; counter++)
    {
        char cmd_string[sizeof WTMP_FILE ".19.gz"];
        Lisp_Object tempname, filename;
        bool delete_flag = 0;

        filename = Qnil;

        tempname = make_formatted_string
                   (cmd_string, "%s.%d", WTMP_FILE, counter);
        if (! NILP (Ffile_exists_p (tempname)))
            filename = tempname;
        else
        {
            tempname = make_formatted_string (cmd_string, "%s.%d.gz",
                                              WTMP_FILE, counter);
            if (! NILP (Ffile_exists_p (tempname)))
            {
                Lisp_Object args[6];

                /* The utmp functions on mescaline.gnu.org accept only
                file names up to 8 characters long.  Choose a 2
                 character long prefix, and call make_temp_file with
                 second arg non-zero, so that it will add not more
                 than 6 characters to the prefix.  */
                filename = Fexpand_file_name (build_string ("wt"),
                                              Vtemporary_file_directory);
                filename = make_temp_name (filename, 1);
                args[0] = build_string ("gzip");
                args[1] = Qnil;
                args[2] = list2 (QCfile, filename);
                args[3] = Qnil;
                args[4] = build_string ("-cd");
                args[5] = tempname;
                Fcall_process (6, args);
                delete_flag = 1;
            }
        }

        if (! NILP (filename))
        {
            get_boot_time_1 (SSDATA (filename), 1);
            if (delete_flag)
                unlink (SSDATA (filename));
        }
    }

    return boot_time;
#else
    return 0;
#endif
}