/* Camicro - Microscope camera viewer. * * Copyright (C) 2019 Nicolas Schodet * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Contact : * Web: http://ni.fr.eu.org/ * Email: */ #define _GNU_SOURCE #include #include #include #include #include "utils.h" void utils_fatal(const char *fmt, ...) { va_list ap; fprintf(stderr, "%s: ", program_invocation_short_name); va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); fputc('\n', stderr); exit(EXIT_FAILURE); } void utils_info(const char *fmt, ...) { va_list ap; fprintf(stderr, "%s: ", program_invocation_short_name); va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); fputc('\n', stderr); } void utils_delay_us(int us) { struct timespec delay, remaining; delay.tv_sec = us / 1000000; delay.tv_nsec = us % 1000000 * 1000; while (nanosleep(&delay, &remaining) == -1) { if (errno == EINTR) delay = remaining; else g_error("can not sleep: %m"); } } void utils_dialog_error(GtkWindow *parent, const char *fmt, ...) { va_list ap; va_start(ap, fmt); char *msg = g_strdup_vprintf(fmt, ap); va_end(ap); GtkWidget *dialog = gtk_message_dialog_new(parent, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", msg); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); g_free(msg); }