Skip to content

Instantly share code, notes, and snippets.

@enhao
enhao / rtc.c
Last active August 29, 2015 14:20
#include <fcntl.h> /* open */
#include <sys/stat.h> /* open */
#include <unistd.h> /* close */
#include <sys/ioctl.h> /* ioctl */
#include <time.h> /* struct tm */
/*
* @param pathname The /dev/rtc (or /dev/rtc0, /dev/rtc1, etc.) can be opened
* only once until it is closed.
#include <netinet/in.h> /* in_addr_t */
in_addr_t calc_broadcast(in_addr_t addr, in_addr_t netmask)
{
return addr | ~netmask;
}
#include <errno.h> /* errno */
#include <arpa/inet.h> /* htonl */
#include <netinet/in.h> /* in_addr_t */
/**
* @param start start IP adress in host byte order
* @param end end IP address in host byte order
* @param addr_cb callback
* @param data callback argument.
* @return If failed, between_addr() returns -1. Otherwise, retrun a value from callback
#include <netinet/in.h> /* in_addr_t */
in_addr_t calc_network(in_addr_t addr, in_addr_t netmask)
{
return addr & netmask;
}
#include <time.h>
double get_timezone(void)
{
time_t t, utc, local;
struct tm tm;
t = time(NULL);
utc = mktime(gmtime_r(&t, &tm));
local = mktime(localtime_r(&t, &tm));
#!/bin/sh
set -e
set -u
function usage() {
echo "Usage: $(basename $0): [-d] args"
echo " -d Make a directory instead of a file."
}