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 <stdio.h>
#include <string.h>

View File

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

View File

@ -1,3 +1,4 @@
// vim:ts=8:expandtab
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
@ -19,7 +20,7 @@ const char *get_battery_info(struct battery *bat) {
present_rate = -1;
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++) {
if (*walk == '\n') {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,3 +1,4 @@
// vim:ts=8:expandtab
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -19,7 +20,7 @@ const char *get_wireless_info() {
memset(buf, 0, sizeof(buf));
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;
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 <string.h>
#include <stdio.h>

View File

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