Skip to content

Instantly share code, notes, and snippets.

View pmj's full-sized avatar

Phil Dennis-Jordan pmj

View GitHub Profile
@pmj
pmj / apfs-timestamp-granularity.c
Last active May 28, 2019 10:18
Testing APFS mtime granularity
#include <stdio.h>
#include <sys/stat.h>
#include <time.h>
#include <mach/clock_types.h>
#include <fcntl.h>
#include <unistd.h>
static const char s_filePath[] = "./testfile"; //"/Volumes/Macintosh HD/Users/phil/Desktop/test/testfile";
int main(int argc, const char * argv[])
float rawBytesToFloat(const char* _buffer)
{
static_assert(sizeof(u_long_type) == sizeof(float),"sizes must match!");
u_long_type net_int;
memcpy(&net_int, _buffer, sizeof(net_int));
u_long_type host_int = asio::detail::socket_ops::network_to_host_long(net_int);
float result;
memcpy(&result, &host_int, sizeof(result));
return result;
}
@pmj
pmj / file-size.c
Last active December 31, 2015 19:18 — forked from weissi/file-size.c
#include <assert.h>
#include <dispatch/dispatch.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/event.h>
#include <sys/event.h>
#include <sys/select.h>
@pmj
pmj / gist:4246325
Created December 9, 2012 18:08
__llvm_gcov_indirect_counter_increment disassembly
(gdb) disassemble
Dump of assembler code for function __llvm_gcov_indirect_counter_increment:
0xffffff7f80902790 <__llvm_gcov_indirect_counter_increment+0>: push %rbp
0xffffff7f80902791 <__llvm_gcov_indirect_counter_increment+1>: mov %rsp,%rbp
0xffffff7f80902794 <__llvm_gcov_indirect_counter_increment+4>: mov (%rdi),%eax
0xffffff7f80902796 <__llvm_gcov_indirect_counter_increment+6>: cmp $0xffffffff,%eax
0xffffff7f8090279b <__llvm_gcov_indirect_counter_increment+11>: mov %rsi,-0x8(%rbp)
0xffffff7f8090279f <__llvm_gcov_indirect_counter_increment+15>: mov %eax,-0xc(%rbp)
0xffffff7f809027a2 <__llvm_gcov_indirect_counter_increment+18>: je 0xffffff7f809027d7 <__llvm_gcov_indirect_counter_increment+71>
0xffffff7f809027a8 <__llvm_gcov_indirect_counter_increment+24>: mov -0xc(%rbp),%eax
Xcode warnings:
Check Switch Statements
Deprecated Functions
Mismatched Return Type
Missing Braces and Parentheses
Pointer Sign Comparison
Sign Comparison
Suspicious Implicit Conversions
Typecheck Calls to printf/scanf
@pmj
pmj / gist:3235684
Created August 2, 2012 09:10
Diffstat of xnu-1699.26.8 (OSX 10.7.4 kernel) and xnu-2050.7.9 (OSX 10.8 kernel)
xnu-1699.26.8/EXTERNAL_HEADERS/mach-o/kld.h |only
xnu-1699.26.8/bsd/crypto/aes |only
xnu-1699.26.8/bsd/crypto/des |only
xnu-1699.26.8/bsd/crypto/sha2 |only
xnu-1699.26.8/bsd/kern/kern_callout.c |only
xnu-1699.26.8/bsd/net/dlil_pvt.h |only
xnu-1699.26.8/bsd/net/pf_mtag.h |only
xnu-1699.26.8/bsd/sys/kern_callout.h |only
xnu-1699.26.8/libkern/crypto/md5.c |only
xnu-1699.26.8/libkern/crypto/sha1.c |only
@pmj
pmj / gist:3075688
Created July 9, 2012 10:34
WIP NSDictionary typed destructuring bind.
// To be used something like this:
SSDC_BIND_DICTIONARY_TYPED(some_dictionary,
NSNumber, count, @"count_key",
NSArray, array_data, kSomeArrayKey,
NSString, a_string, stringkey);
/* this produces the variables count, array_data, and a_string, which
* have the specified static AND dynamic types (i.e. if objectForKey:stringKey
* is not actually an NSString, a_string will contain nil, not the object that
* will throw exceptions when used as a string.
@pmj
pmj / gist:2944912
Created June 17, 2012 15:46
Super safe container_of macro for structs
/** genc_container_of(obj, cont_type, member_name)
* Get pointer to struct object from a pointer to one of its members.
* obj - pointer to a struct member, or NULL
* cont_type - structure type of the containing object
* member_name - name of the member of cont_type referenced by obj
*
* Similar to Linux's container_of macro, except it also handles NULL pointers
* correctly, which is to say it evaluates to NULL when the obj is NULL. We also
* try to support non-GCC compilers which don't support the ({ }) expression
* syntax.
@pmj
pmj / gist:2944868
Created June 17, 2012 15:36
Safe Objective-C cast with superclass type check
#define SSDC_CAST(TYPE, EXPR) \
({ \
__typeof(EXPR) _cast_expr_tmp = (EXPR); \
__typeof(EXPR) _super_check_ref __attribute__((unused)) = (TYPE*)nil; \
([_cast_expr_tmp isKindOfClass:[TYPE class]]) ? (TYPE*)_cast_expr_tmp : nil; \
})
@pmj
pmj / gist:2660790
Created May 11, 2012 16:31
64-bit * 64-bit -> 128-bit unsigned integer long multiplication
#include <stdio.h>
#include <stdint.h>
#include <assert.h>
#include <stdlib.h>
struct big64
{
uint32_t v[2]; /* num = v[0] + (v[1] << 32) - "little endian" */
};
typedef struct big64 big64_t;