コード例 #1
0
ファイル: status_ui.c プロジェクト: imbyungjun/TIL
char* ioctl_get_msg(int file_desc) {
    int ret_val;
    char message[MAX_SIZE];
  
    ret_val = ioctl(file_desc, IOCTL_GET_MSG, message);
    if (ret_val < 0) {
        printf("ioctl_get_msg failed:%d\n", ret_val);
        exit(-1); 
    }

	print_battery(strtol(message, 0, 10));
}
コード例 #2
0
ファイル: status.c プロジェクト: Theta91/dotfiles
int main(void) {
    FILE *fp_mail;
    char *status = (char *)alloca(200);
    int b, d, m;
    b = BATTERY_INTERVAL;
    d = DATE_INTERVAL;
    m = MAIL_INTERVAL;

    struct timespec interval = {
        .tv_sec  = UPDATE_INTERVAL,
        .tv_nsec = 0 };
    int sockfd = socket(AF_INET, SOCK_DGRAM, 0);

    for ( ; ; nanosleep(&interval, NULL)) {
        if (++b > BATTERY_INTERVAL) {
            print_battery();
            b = 0; }
        if (++d > DATE_INTERVAL) {
            print_time();
            d = 0; }
        if (++m > MAIL_INTERVAL) {
            if (print_mail(fp_mail) == 0) {
                m = 0; }
            if (errno == EBADF) {
                fp_mail = mail_init(); } }
        if (sockfd != -1) {
            print_iw(sockfd); }
        strncpy(_root, print_free("/"), _FREE_LEN);
        strncpy(_home, print_free("/home"), _FREE_LEN);
        print_time();
        print_cpu();
        print_memory();
        snprintf(status, 200, "%s %s | %s | %s | %s | %s | %s | %s"
                            , _root, _home, _iw, _battery, _mail, _cpu
                            , _mem, _date);
        printf("%s\n", status);

        }//break; }

    pclose(fp_mail);
    cleanup(sockfd); }

double get_battery_stats(const char *path) {
    FILE *stats;
    double value = 0;

    if ((stats = fopen(path, "r"))== NULL) {
        return -1; }
    fscanf(stats, "%lf", &value);
    fclose(stats);

    return value; }