#include <caml/memory.h>
#include <caml/mlvalues.h>
#include <caml/unixsupport.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>

#include "selfie.h"

CAMLprim value
caml_snap(value path)
{
	int fd, ret;

	CAMLparam1(path);
	fd = open(String_val(path), O_CREAT|O_WRONLY, 0755);
	if (fd < 0)
		uerror("open", path);
	ret = selfie(fd);
	if (ret != 1)
		close(fd);
	if (ret < 0)
		uerror("selfie", Nothing);
	CAMLreturn(Val_unit);
}
