+// vim:ts=8:expandtab
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
+// vim:ts=8:expandtab
#include <sys/types.h>
#include <string.h>
#include <stdarg.h>
*
*/
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);
}
/*
+// vim:ts=8:expandtab
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
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') {
+// vim:ts=8:expandtab
#include <stdlib.h>
#include <limits.h>
#include <stdio.h>
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");
+// vim:ts=8:expandtab
#include <string.h>
#include <limits.h>
#include <stdio.h>
+// vim:ts=8:expandtab
#include <net/if.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
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;
}
+// vim:ts=8:expandtab
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
*
*/
const char *get_ipv6_addr() {
- 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;
-
- 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;
- }
-
- 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";
- }
-
- 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);
-
- free(result);
- return buf;
- }
-
- free(result);
- return "no IP";
+ 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;
+
+ 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;
+ }
+
+ 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";
+ }
+
+ 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);
+
+ free(result);
+ return buf;
+ }
+
+ free(result);
+ return "no IP";
}
+// 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;
}
+// vim:ts=8:expandtab
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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)) {
+// vim:ts=8:expandtab
#include <stdbool.h>
#include <string.h>
#include <stdio.h>
+// vim:ts=8:expandtab
#include <stdbool.h>
#include <glob.h>
#include <string.h>