Add modelines and retab! all files

This commit is contained in:
Michael Stapelberg 2009-07-21 20:26:53 +02:00
parent 34ba9fa908
commit 230f3167b7
11 changed files with 77 additions and 66 deletions

View File

@ -1,3 +1,4 @@
// vim:ts=8:expandtab
#include <sys/stat.h> #include <sys/stat.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>

View File

@ -1,3 +1,4 @@
// vim:ts=8:expandtab
#include <sys/types.h> #include <sys/types.h>
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
@ -13,13 +14,13 @@
* *
*/ */
void slurp(char *filename, char *destination, int size) { void slurp(char *filename, char *destination, int size) {
int fd; int fd;
if ((fd = open(filename, O_RDONLY)) == -1) if ((fd = open(filename, O_RDONLY)) == -1)
die("Could not open \"%s\"\n", filename); die("Could not open \"%s\"\n", filename);
(void)read(fd, destination, size); (void)read(fd, destination, size);
(void)close(fd); (void)close(fd);
} }
/* /*

View File

@ -1,3 +1,4 @@
// vim:ts=8:expandtab
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
@ -19,7 +20,7 @@ const char *get_battery_info(struct battery *bat) {
present_rate = -1; present_rate = -1;
charging_status_t status = CS_DISCHARGING; charging_status_t status = CS_DISCHARGING;
slurp(bat->path, buf, sizeof(buf)); slurp(bat->path, buf, sizeof(buf));
for (walk = buf, last = buf; (walk-buf) < 1024; walk++) { for (walk = buf, last = buf; (walk-buf) < 1024; walk++) {
if (*walk == '\n') { if (*walk == '\n') {

View File

@ -1,3 +1,4 @@
// vim:ts=8:expandtab
#include <stdlib.h> #include <stdlib.h>
#include <limits.h> #include <limits.h>
#include <stdio.h> #include <stdio.h>
@ -13,8 +14,8 @@ const char *get_cpu_temperature_info() {
static char buf[16]; static char buf[16];
long int temp; long int temp;
slurp(thermal_zone, buf, sizeof(buf)); slurp(thermal_zone, buf, sizeof(buf));
temp = strtol(buf, NULL, 10); temp = strtol(buf, NULL, 10);
if (temp == LONG_MIN || temp == LONG_MAX || temp <= 0) if (temp == LONG_MIN || temp == LONG_MAX || temp <= 0)
(void)snprintf(buf, sizeof(buf), "T: ? C"); (void)snprintf(buf, sizeof(buf), "T: ? C");

View File

@ -1,3 +1,4 @@
// vim:ts=8:expandtab
#include <string.h> #include <string.h>
#include <limits.h> #include <limits.h>
#include <stdio.h> #include <stdio.h>

View File

@ -1,3 +1,4 @@
// vim:ts=8:expandtab
#include <net/if.h> #include <net/if.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
@ -32,11 +33,11 @@ const char *get_ip_addr(const char *interface) {
if (ioctl(general_socket, SIOCGIFADDR, &ifr) < 0) if (ioctl(general_socket, SIOCGIFADDR, &ifr) < 0)
return "no IP"; return "no IP";
int ret; int ret;
if ((ret = getnameinfo(&ifr.ifr_addr, len, part, sizeof(part), NULL, 0, NI_NUMERICHOST)) != 0) { if ((ret = getnameinfo(&ifr.ifr_addr, len, part, sizeof(part), NULL, 0, NI_NUMERICHOST)) != 0) {
fprintf(stderr, "getnameinfo(): %s\n", gai_strerror(ret)); fprintf(stderr, "getnameinfo(): %s\n", gai_strerror(ret));
return "no IP"; return "no IP";
} }
return part; return part;
} }

View File

@ -1,3 +1,4 @@
// vim:ts=8:expandtab
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
@ -12,50 +13,50 @@
* *
*/ */
const char *get_ipv6_addr() { const char *get_ipv6_addr() {
static char buf[INET6_ADDRSTRLEN+1]; static char buf[INET6_ADDRSTRLEN+1];
struct addrinfo hints; struct addrinfo hints;
struct addrinfo *result, *resp; struct addrinfo *result, *resp;
int fd; int fd;
memset(&hints, 0, sizeof(struct addrinfo)); memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_INET6; hints.ai_family = AF_INET6;
if (getaddrinfo("k.root-servers.net", "domain", &hints, &result) != 0) { if (getaddrinfo("k.root-servers.net", "domain", &hints, &result) != 0) {
perror("getaddrinfo()"); perror("getaddrinfo()");
return "no IP"; return "no IP";
} }
for (resp = result; resp != NULL; resp = resp->ai_next) { for (resp = result; resp != NULL; resp = resp->ai_next) {
if ((fd = socket(resp->ai_family, SOCK_STREAM, 0)) == -1) { if ((fd = socket(resp->ai_family, SOCK_STREAM, 0)) == -1) {
perror("socket()"); perror("socket()");
continue; continue;
} }
if (connect(fd, resp->ai_addr, resp->ai_addrlen) == -1) { if (connect(fd, resp->ai_addr, resp->ai_addrlen) == -1) {
perror("connect()"); perror("connect()");
continue; continue;
} }
struct sockaddr_storage local; struct sockaddr_storage local;
socklen_t local_len = sizeof(struct sockaddr_storage); socklen_t local_len = sizeof(struct sockaddr_storage);
if (getsockname(fd, (struct sockaddr*)&local, &local_len) == -1) { if (getsockname(fd, (struct sockaddr*)&local, &local_len) == -1) {
perror("getsockname()"); perror("getsockname()");
return "no IP"; return "no IP";
} }
memset(buf, 0, INET6_ADDRSTRLEN + 1); memset(buf, 0, INET6_ADDRSTRLEN + 1);
int ret; int ret;
if ((ret = getnameinfo((struct sockaddr*)&local, local_len, buf, sizeof(buf), NULL, 0, NI_NUMERICHOST)) != 0) { if ((ret = getnameinfo((struct sockaddr*)&local, local_len, buf, sizeof(buf), NULL, 0, NI_NUMERICHOST)) != 0) {
fprintf(stderr, "getnameinfo(): %s\n", gai_strerror(ret)); fprintf(stderr, "getnameinfo(): %s\n", gai_strerror(ret));
return "no IP"; return "no IP";
} }
(void)close(fd); (void)close(fd);
free(result); free(result);
return buf; return buf;
} }
free(result); free(result);
return "no IP"; return "no IP";
} }

View File

@ -1,25 +1,26 @@
// vim:ts=8:expandtab
#include "i3status.h" #include "i3status.h"
const char *get_load() { const char *get_load() {
static char part[512]; static char part[512];
/* Get load */ /* Get load */
#ifdef LINUX #ifdef LINUX
slurp("/proc/loadavg", part, sizeof(part)); slurp("/proc/loadavg", part, sizeof(part));
*skip_character(part, ' ', 3) = '\0'; *skip_character(part, ' ', 3) = '\0';
#else #else
/* TODO: correctly check for NetBSD, check if it works the same on *BSD */ /* TODO: correctly check for NetBSD, check if it works the same on *BSD */
struct loadavg load; struct loadavg load;
size_t length = sizeof(struct loadavg); size_t length = sizeof(struct loadavg);
int mib[2] = { CTL_VM, VM_LOADAVG }; int mib[2] = { CTL_VM, VM_LOADAVG };
if (sysctl(mib, 2, &load, &length, NULL, 0) < 0) if (sysctl(mib, 2, &load, &length, NULL, 0) < 0)
die("Could not sysctl({ CTL_VM, VM_LOADAVG })\n"); die("Could not sysctl({ CTL_VM, VM_LOADAVG })\n");
double scale = load.fscale; double scale = load.fscale;
(void)snprintf(part, sizeof(part), "%.02f %.02f %.02f", (void)snprintf(part, sizeof(part), "%.02f %.02f %.02f",
(double)load.ldavg[0] / scale, (double)load.ldavg[0] / scale,
(double)load.ldavg[1] / scale, (double)load.ldavg[1] / scale,
(double)load.ldavg[2] / scale); (double)load.ldavg[2] / scale);
#endif #endif
return part; return part;
} }

View File

@ -1,3 +1,4 @@
// vim:ts=8:expandtab
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -19,7 +20,7 @@ const char *get_wireless_info() {
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
memset(part, 0, sizeof(part)); memset(part, 0, sizeof(part));
slurp("/proc/net/wireless", buf, sizeof(buf)); slurp("/proc/net/wireless", buf, sizeof(buf));
interfaces = skip_character(buf, '\n', 1) + 1; interfaces = skip_character(buf, '\n', 1) + 1;
while ((interfaces = skip_character(interfaces, '\n', 1)+1) < buf+strlen(buf)) { while ((interfaces = skip_character(interfaces, '\n', 1)+1) < buf+strlen(buf)) {

View File

@ -1,3 +1,4 @@
// vim:ts=8:expandtab
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>

View File

@ -1,3 +1,4 @@
// vim:ts=8:expandtab
#include <stdbool.h> #include <stdbool.h>
#include <glob.h> #include <glob.h>
#include <string.h> #include <string.h>