int
main(int argc, char **argv)
{
    assert(argc > 1);
    int n = atoi(argv[1]);

    int fd = open("/dev/urandom", O_RDONLY, 0);
    if (fd < 0)
        err(1, "open failed");

    size_t s = sizeof(u64) * (unsigned int)n;
    u64 *a = malloc(s);

    if (read(fd, (char*)a, s) < 0)
        err(1, "read failed");

    if (close(fd))
        err(1, "close failed");

    double start = l_time();
    radix_sort_64(a, n);
    printf("Sorted %d ints in %f seconds.\n", n, l_time() - start);

    //for (int i = n-10; i < n; i++)
    //    printf("%d: %zu\n", i, a[i]);

    free(a);
    return 0;
}
Exemple #2
0
gint
main(gint argc, gchar *argv[]) {
    gboolean *nonblock = NULL;
    gchar **uris = NULL;
    pid_t pid, sid;

    globalconf.starttime = l_time();

    /* clean up any zombies */
    struct sigaction sigact;
    sigact.sa_handler=sigchld;
    sigemptyset (&sigact.sa_mask);
    sigact.sa_flags = SA_NOCLDSTOP;
    if (sigaction(SIGCHLD, &sigact, NULL))
        fatal("Can't install SIGCHLD handler");

    /* set numeric locale to C (required for compatibility with
       LuaJIT and luakit scripts) */
    gtk_set_locale();
    gtk_disable_setlocale();
    setlocale(LC_NUMERIC, "C");

    /* parse command line opts and get uris to load */
    uris = parseopts(&argc, argv, &nonblock);

    /* if non block mode - respawn, detach and continue in child */
    if (nonblock) {
        pid = fork();
        if (pid < 0) {
            fatal("Cannot fork: %d", errno);
        } else if (pid > 0) {
            exit(EXIT_SUCCESS);
        }
        sid = setsid();
        if (sid < 0) {
            fatal("New SID creation failure: %d", errno);
        }
    }

    gtk_init(&argc, &argv);

    init_directories();
    init_lua(uris);

    /* hide command line parameters so process lists don't leak (possibly
       confidential) URLs */
    for (gint i = 1; i < argc; i++)
        memset(argv[i], 0, strlen(argv[i]));

    /* parse and run configuration file */
    if(!luaH_parserc(globalconf.confpath, TRUE))
        fatal("couldn't find rc file");

    if (!globalconf.windows->len)
        fatal("no windows spawned by rc file, exiting");

    gtk_main();
    return EXIT_SUCCESS;
}