├── compat ├── jansson-2.5 │ ├── m4 │ │ └── .gitignore │ ├── jansson.pc.in │ ├── Makefile.am │ ├── src │ │ ├── Makefile.am │ │ ├── strbuffer.h │ │ ├── utf.h │ │ ├── memory.c │ │ ├── jansson_config.h.in │ │ ├── jansson.def │ │ ├── error.c │ │ ├── jansson_private.h │ │ ├── strbuffer.c │ │ ├── strconv.c │ │ └── utf.c │ ├── LICENSE │ ├── configure.ac │ └── README.rst ├── .gitignore ├── libusb-1.0 │ ├── m4 │ │ └── .gitignore │ ├── libusb │ │ ├── os │ │ │ ├── poll_posix.h │ │ │ ├── threads_posix.c │ │ │ ├── threads_posix.h │ │ │ ├── threads_windows.h │ │ │ └── poll_windows.h │ │ ├── version.h │ │ ├── Makefile.am │ │ ├── libusb-1.0.rc │ │ └── hotplug.h │ ├── TODO │ ├── libusb-1.0.pc.in │ ├── Makefile.am │ ├── README │ ├── AUTHORS │ ├── NEWS │ └── PORTING └── Makefile.am ├── ADL_SDK ├── .gitignore └── readme.txt ├── API.class ├── MCast.class ├── LICENSE ├── bitstreams ├── fpgaminer_top_fixed7_197MHz.ncd └── COPYING_fpgaminer ├── ChangeLog ├── ccan ├── Makefile.am ├── opt │ ├── test │ │ ├── compile_ok-const-arg.c │ │ ├── utils.h │ │ ├── run-no-options.c │ │ ├── run-correct-reporting.c │ │ ├── run-iter.c │ │ ├── utils.c │ │ ├── run-checkopt.c │ │ └── run-usage.c │ ├── private.h │ ├── _info │ ├── usage.c │ ├── parse.c │ └── helpers.c ├── compiler │ ├── test │ │ ├── run-is_compile_constant.c │ │ └── compile_fail-printf.c │ └── _info └── typesafe_cb │ └── test │ ├── compile_ok-typesafe_cb-NULL.c │ ├── compile_fail-cast_if_type-promotable.c │ ├── compile_fail-typesafe_cb_cast.c │ ├── compile_fail-typesafe_cb-int.c │ ├── compile_fail-typesafe_cb_postargs.c │ ├── compile_fail-typesafe_cb_preargs.c │ ├── compile_fail-typesafe_cb_cast-multi.c │ ├── compile_fail-typesafe_cb.c │ ├── compile_ok-typesafe_cb_cast.c │ ├── compile_ok-typesafe_cb-undefined.c │ ├── compile_ok-typesafe_cb-vars.c │ └── run.c ├── autogen.sh ├── AUTHORS ├── lib ├── memchr.valgrind ├── dummy.c ├── sig-handler.h ├── stddef.in.h └── memmem.c ├── example.conf ├── .gitignore ├── scrypt.h ├── m4 ├── wchar_t.m4 ├── sigaction.m4 ├── 00gnulib.m4 ├── gnulib-cache.m4 ├── signalblocking.m4 ├── gnulib-tool.m4 ├── stddef_h.m4 ├── mmap-anon.m4 ├── multiarch.m4 ├── warn-on-use.m4 ├── signal_h.m4 ├── memchr.m4 ├── onceonly.m4 └── extensions.m4 ├── mknsis.sh ├── adl.h ├── driver-opencl.h ├── arg-nonnull.h ├── libbitfury.h ├── ocl.h ├── driver-drillbit.h ├── api-example.py ├── 01-cgminer.rules ├── compat.h ├── hexdump.c ├── logging.c ├── driver-bitfury.h ├── api-example.php ├── sha2.h ├── logging.h ├── mcp2210.h ├── fpgautils.h ├── usbtest.py ├── Makefile.am ├── bitmain-readme.txt ├── klist.h ├── bench_block.h ├── API.java └── bitforce-firmware-flash.c /compat/jansson-2.5/m4/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /ADL_SDK/.gitignore: -------------------------------------------------------------------------------- 1 | adl_defines.h 2 | adl_sdk.h 3 | adl_structures.h 4 | -------------------------------------------------------------------------------- /API.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creating/cgminer/master/API.class -------------------------------------------------------------------------------- /MCast.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creating/cgminer/master/MCast.class -------------------------------------------------------------------------------- /compat/.gitignore: -------------------------------------------------------------------------------- 1 | libusb-1.0/libusb/libusb-1.0.la 2 | libusb-1.0/libusb/*.lo 3 | libusb-1.0/libusb/os/*.lo 4 | -------------------------------------------------------------------------------- /compat/libusb-1.0/m4/.gitignore: -------------------------------------------------------------------------------- 1 | libtool.m4 2 | lt~obsolete.m4 3 | ltoptions.m4 4 | ltsugar.m4 5 | ltversion.m4 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Cgminer is available under the terms of the GNU Public License version 3. 2 | 3 | See COPYING for details. 4 | -------------------------------------------------------------------------------- /bitstreams/fpgaminer_top_fixed7_197MHz.ncd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creating/cgminer/master/bitstreams/fpgaminer_top_fixed7_197MHz.ncd -------------------------------------------------------------------------------- /compat/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | SUBDIRS = jansson-2.5 3 | 4 | if WANT_USBUTILS 5 | if WANT_STATIC_LIBUSB 6 | SUBDIRS += libusb-1.0 7 | endif 8 | endif 9 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | See git repository ('git log') for full changelog. 2 | 3 | Git repo can be found at: 4 | https://github.com/ckolivas/cgminer 5 | 6 | The NEWS file contains most of the changelog 7 | -------------------------------------------------------------------------------- /ADL_SDK/readme.txt: -------------------------------------------------------------------------------- 1 | Please insert AMD ADL files adl_defines.h adl_sdk.h adl_structures.h here. 2 | They can be found here: 3 | http://developer.amd.com/tools/graphics-development/display-library-adl-sdk/ 4 | -------------------------------------------------------------------------------- /ccan/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LIBRARIES = libccan.a 2 | 3 | libccan_a_SOURCES = compiler/compiler.h opt/helpers.c opt/opt.c opt/opt.h opt/parse.c opt/private.h opt/usage.c typesafe_cb/typesafe_cb.h 4 | libccan_a_CPPFLAGS = -I$(top_srcdir) 5 | -------------------------------------------------------------------------------- /compat/libusb-1.0/libusb/os/poll_posix.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBUSB_POLL_POSIX_H 2 | #define LIBUSB_POLL_POSIX_H 3 | 4 | #define usbi_write write 5 | #define usbi_read read 6 | #define usbi_close close 7 | #define usbi_pipe pipe 8 | #define usbi_poll poll 9 | 10 | #endif /* LIBUSB_POLL_POSIX_H */ 11 | -------------------------------------------------------------------------------- /compat/jansson-2.5/jansson.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=${prefix}/include 5 | 6 | Name: Jansson 7 | Description: Library for encoding, decoding and manipulating JSON data 8 | Version: @VERSION@ 9 | Libs: -L${libdir} -ljansson 10 | Cflags: -I${includedir} 11 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | bs_dir="$(dirname $(readlink -f $0))" 3 | 4 | #Some versions of libtoolize don't like there being no ltmain.sh file already 5 | touch "${bs_dir}"/ltmain.sh 6 | autoreconf -fi "${bs_dir}" 7 | 8 | if test -z "$NOCONFIGURE" ; then 9 | echo 'Configuring...' 10 | "$bs_dir"/configure "$@" 11 | fi 12 | -------------------------------------------------------------------------------- /compat/libusb-1.0/TODO: -------------------------------------------------------------------------------- 1 | for 1.1 or future 2 | ================== 3 | optional timerfd support (runtime detection) 4 | notifications of hotplugged/unplugged devices 5 | offer API to create/destroy handle_events thread 6 | isochronous sync I/O? 7 | exposing of parent-child device relationships 8 | "usb primer" introduction docs 9 | more examples 10 | -------------------------------------------------------------------------------- /compat/libusb-1.0/libusb-1.0.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libusb-1.0 7 | Description: C API for USB device access from Linux, Mac OS X, OpenBSD, NetBSD and Windows userspace 8 | Version: @VERSION@ 9 | Libs: -L${libdir} -lusb-1.0 10 | Libs.private: @LIBS@ 11 | Cflags: -I${includedir}/libusb-1.0 12 | 13 | -------------------------------------------------------------------------------- /ccan/opt/test/compile_ok-const-arg.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | opt_register_noarg("-v", opt_version_and_exit, 10 | (const char *)"1.2.3", 11 | (const char *)"Print version"); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /ccan/compiler/test/run-is_compile_constant.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | plan_tests(2); 7 | 8 | ok1(!IS_COMPILE_CONSTANT(argc)); 9 | #if HAVE_BUILTIN_CONSTANT_P 10 | ok1(IS_COMPILE_CONSTANT(7)); 11 | #else 12 | pass("If !HAVE_BUILTIN_CONSTANT_P, IS_COMPILE_CONSTANT always false"); 13 | #endif 14 | return exit_status(); 15 | } 16 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Current maintainers and active developers: 2 | Main code+USB+ASIC+maintainer: Con Kolivas 15qSxP1SQcUX3o4nhkfdbgyoWEFMomJ4rZ 3 | API+USB+FPGA+ASIC: Andrew Smith 1Jjk2LmktEQKnv8r2cZ9MvLiZwZ9gxabKm 4 | 5 | Legacy: 6 | Original CPU mining software: Jeff Garzik 7 | BitFORCE FPGA mining and refactor: Luke Dashjr 1NbRmS6a4dniwHHoSS9v3tEYUpP1Z5VVdL 8 | -------------------------------------------------------------------------------- /ccan/compiler/test/compile_fail-printf.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void PRINTF_FMT(2,3) my_printf(int x, const char *fmt, ...) 4 | { 5 | } 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | unsigned int i = 0; 10 | 11 | my_printf(1, "Not a pointer " 12 | #ifdef FAIL 13 | "%p", 14 | #if !HAVE_ATTRIBUTE_PRINTF 15 | #error "Unfortunately we don't fail if !HAVE_ATTRIBUTE_PRINTF." 16 | #endif 17 | #else 18 | "%i", 19 | #endif 20 | i); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /compat/jansson-2.5/Makefile.am: -------------------------------------------------------------------------------- 1 | ACLOCAL_AMFLAGS = -I m4 2 | 3 | EXTRA_DIST = CHANGES LICENSE README.rst 4 | SUBDIRS = src 5 | 6 | # "make distcheck" builds the dvi target, so use it to check that the 7 | # documentation is built correctly. 8 | dvi: 9 | $(MAKE) SPHINXOPTS_EXTRA=-W html 10 | 11 | pkgconfigdir = $(libdir)/pkgconfig 12 | pkgconfig_DATA = jansson.pc 13 | 14 | if GCC 15 | # These flags are gcc specific 16 | export AM_CFLAGS = -Wall -Wextra -Wdeclaration-after-statement 17 | endif 18 | -------------------------------------------------------------------------------- /lib/memchr.valgrind: -------------------------------------------------------------------------------- 1 | # Suppress a valgrind message about use of uninitialized memory in memchr(). 2 | # POSIX states that when the character is found, memchr must not read extra 3 | # bytes in an overestimated length (for example, where memchr is used to 4 | # implement strnlen). However, we use a safe word read to provide a speedup. 5 | { 6 | memchr-value4 7 | Memcheck:Value4 8 | fun:rpl_memchr 9 | } 10 | { 11 | memchr-value8 12 | Memcheck:Value8 13 | fun:rpl_memchr 14 | } 15 | -------------------------------------------------------------------------------- /example.conf: -------------------------------------------------------------------------------- 1 | { 2 | "pools" : [ 3 | { 4 | "url" : "http://url1:8332", 5 | "user" : "user1", 6 | "pass" : "pass1" 7 | }, 8 | { 9 | "url" : "http://url2:8344", 10 | "user" : "user2", 11 | "pass" : "pass2" 12 | }, 13 | { 14 | "url" : "http://url3:8332", 15 | "user" : "user3", 16 | "pass" : "pass3" 17 | } 18 | ], 19 | 20 | "failover-only" : true, 21 | "no-submit-stale" : true, 22 | "api-listen" : true, 23 | "api-port" : "4028", 24 | "api-allow" : "W:192.168.1.0/24,W:127.0.0.1" 25 | } 26 | -------------------------------------------------------------------------------- /ccan/typesafe_cb/test/compile_ok-typesafe_cb-NULL.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* NULL args for callback function should be OK for normal and _def. */ 5 | 6 | static void _register_callback(void (*cb)(const void *arg), const void *arg) 7 | { 8 | } 9 | 10 | #define register_callback(cb, arg) \ 11 | _register_callback(typesafe_cb(void, const void *, (cb), (arg)), (arg)) 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | register_callback(NULL, "hello world"); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /compat/jansson-2.5/src/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = jansson.def 2 | 3 | include_HEADERS = jansson.h jansson_config.h 4 | 5 | lib_LTLIBRARIES = libjansson.la 6 | libjansson_la_SOURCES = \ 7 | dump.c \ 8 | error.c \ 9 | hashtable.c \ 10 | hashtable.h \ 11 | jansson_private.h \ 12 | load.c \ 13 | memory.c \ 14 | pack_unpack.c \ 15 | strbuffer.c \ 16 | strbuffer.h \ 17 | strconv.c \ 18 | utf.c \ 19 | utf.h \ 20 | value.c 21 | libjansson_la_LDFLAGS = \ 22 | -no-undefined \ 23 | -export-symbols-regex '^json_' \ 24 | -version-info 9:0:5 25 | -------------------------------------------------------------------------------- /compat/libusb-1.0/libusb/version.h: -------------------------------------------------------------------------------- 1 | /* This file is parsed by m4 and windres and RC.EXE so please keep it simple. */ 2 | #ifndef LIBUSB_MAJOR 3 | #define LIBUSB_MAJOR 1 4 | #endif 5 | #ifndef LIBUSB_MINOR 6 | #define LIBUSB_MINOR 0 7 | #endif 8 | #ifndef LIBUSB_MICRO 9 | #define LIBUSB_MICRO 16 10 | #endif 11 | /* LIBUSB_NANO may be used for Windows internal versioning. 0 means unused. */ 12 | #ifndef LIBUSB_NANO 13 | #define LIBUSB_NANO 0 14 | #endif 15 | /* LIBUSB_RC is the release candidate suffix. Should normally be empty. */ 16 | #ifndef LIBUSB_RC 17 | #define LIBUSB_RC "-rc10" 18 | #endif 19 | -------------------------------------------------------------------------------- /ccan/typesafe_cb/test/compile_fail-cast_if_type-promotable.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static void _set_some_value(void *val) 5 | { 6 | } 7 | 8 | #define set_some_value(expr) \ 9 | _set_some_value(typesafe_cb_cast(void *, long, (expr))) 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | #ifdef FAIL 14 | bool x = 0; 15 | #if !HAVE_TYPEOF||!HAVE_BUILTIN_CHOOSE_EXPR||!HAVE_BUILTIN_TYPES_COMPATIBLE_P 16 | #error "Unfortunately we don't fail if typesafe_cb_cast is a noop." 17 | #endif 18 | #else 19 | long x = 0; 20 | #endif 21 | set_some_value(x); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | cgminer 2 | cgminer.exe 3 | minerd 4 | minerd.exe 5 | *.o 6 | *.bin 7 | 8 | autom4te.cache 9 | .deps 10 | 11 | Makefile 12 | Makefile.in 13 | INSTALL 14 | aclocal.m4 15 | configure 16 | depcomp 17 | missing 18 | install-sh 19 | stamp-h1 20 | cpuminer-config.h* 21 | compile 22 | config.log 23 | config.status 24 | config.guess 25 | config.sub 26 | 27 | mingw32-config.cache 28 | 29 | *~ 30 | 31 | ext_deps 32 | config.h.in 33 | config.h 34 | 35 | ccan/libccan.a 36 | lib/arg-nonnull.h 37 | lib/c++defs.h 38 | lib/libgnu.a 39 | lib/signal.h 40 | lib/string.h 41 | lib/stdint.h 42 | lib/warn-on-use.h 43 | 44 | mkinstalldirs 45 | 46 | *.swp 47 | -------------------------------------------------------------------------------- /scrypt.h: -------------------------------------------------------------------------------- 1 | #ifndef SCRYPT_H 2 | #define SCRYPT_H 3 | 4 | #include "miner.h" 5 | 6 | #ifdef USE_SCRYPT 7 | extern int scrypt_test(unsigned char *pdata, const unsigned char *ptarget, 8 | uint32_t nonce); 9 | extern void scrypt_regenhash(struct work *work); 10 | 11 | #else /* USE_SCRYPT */ 12 | static inline int scrypt_test(__maybe_unused unsigned char *pdata, 13 | __maybe_unused const unsigned char *ptarget, 14 | __maybe_unused uint32_t nonce) 15 | { 16 | return 0; 17 | } 18 | 19 | static inline void scrypt_regenhash(__maybe_unused struct work *work) 20 | { 21 | } 22 | #endif /* USE_SCRYPT */ 23 | 24 | #endif /* SCRYPT_H */ 25 | -------------------------------------------------------------------------------- /ccan/typesafe_cb/test/compile_fail-typesafe_cb_cast.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void _set_some_value(void *val); 4 | 5 | void _set_some_value(void *val) 6 | { 7 | } 8 | 9 | #define set_some_value(expr) \ 10 | _set_some_value(typesafe_cb_cast(void *, unsigned long, (expr))) 11 | 12 | int main(int argc, char *argv[]) 13 | { 14 | #ifdef FAIL 15 | int x = 0; 16 | set_some_value(x); 17 | #if !HAVE_TYPEOF||!HAVE_BUILTIN_CHOOSE_EXPR||!HAVE_BUILTIN_TYPES_COMPATIBLE_P 18 | #error "Unfortunately we don't fail if typesafe_cb_cast is a noop." 19 | #endif 20 | #else 21 | void *p = 0; 22 | set_some_value(p); 23 | #endif 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /ccan/opt/test/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef CCAN_OPT_TEST_UTILS_H 2 | #define CCAN_OPT_TEST_UTILS_H 3 | #include 4 | #include 5 | 6 | bool parse_args(int *argc, char ***argv, ...); 7 | extern char *err_output; 8 | void save_err_output(const char *fmt, ...); 9 | 10 | extern unsigned int test_cb_called; 11 | char *test_noarg(void *arg); 12 | char *test_arg(const char *optarg, const char *arg); 13 | void show_arg(char buf[OPT_SHOW_LEN], const char *arg); 14 | 15 | extern struct opt_table short_table[]; 16 | extern struct opt_table long_table[]; 17 | extern struct opt_table long_and_short_table[]; 18 | extern struct opt_table subtables[]; 19 | #endif /* CCAN_OPT_TEST_UTILS_H */ 20 | -------------------------------------------------------------------------------- /ccan/opt/private.h: -------------------------------------------------------------------------------- 1 | #ifndef CCAN_OPT_PRIVATE_H 2 | #define CCAN_OPT_PRIVATE_H 3 | 4 | extern struct opt_table *opt_table; 5 | extern unsigned int opt_count, opt_num_short, opt_num_short_arg, opt_num_long; 6 | 7 | extern const char *opt_argv0; 8 | 9 | #define subtable_of(entry) ((struct opt_table *)((entry)->names)) 10 | 11 | const char *first_sopt(unsigned *i); 12 | const char *next_sopt(const char *names, unsigned *i); 13 | const char *first_lopt(unsigned *i, unsigned *len); 14 | const char *next_lopt(const char *p, unsigned *i, unsigned *len); 15 | 16 | int parse_one(int *argc, char *argv[], unsigned *offset, 17 | void (*errlog)(const char *fmt, ...)); 18 | 19 | #endif /* CCAN_OPT_PRIVATE_H */ 20 | -------------------------------------------------------------------------------- /compat/libusb-1.0/Makefile.am: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS = dist-bzip2 no-dist-gzip 2 | ACLOCAL_AMFLAGS = -I m4 3 | DISTCLEANFILES = libusb-1.0.pc 4 | MAINTAINERCLEANFILES = ChangeLog 5 | EXTRA_DIST = TODO PORTING 6 | SUBDIRS = libusb 7 | 8 | pkgconfigdir=$(libdir)/pkgconfig 9 | pkgconfig_DATA=libusb-1.0.pc 10 | 11 | .PHONY: ChangeLog dist-up 12 | ChangeLog: 13 | git --git-dir $(top_srcdir)/.git log > ChangeLog || touch ChangeLog 14 | 15 | dist-hook: ChangeLog 16 | 17 | reldir = .release/$(distdir) 18 | dist-up: dist 19 | rm -rf $(reldir) 20 | mkdir -p $(reldir) 21 | cp $(distdir).tar.bz2 $(reldir) 22 | rsync -rv $(reldir) frs.sourceforge.net:/home/frs/project/l/li/libusb/libusb-1.0/ 23 | rm -rf $(reldir) 24 | 25 | -------------------------------------------------------------------------------- /ccan/typesafe_cb/test/compile_fail-typesafe_cb-int.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void _callback(void (*fn)(void *arg), void *arg); 5 | void _callback(void (*fn)(void *arg), void *arg) 6 | { 7 | fn(arg); 8 | } 9 | 10 | /* Callback is set up to warn if arg isn't a pointer (since it won't 11 | * pass cleanly to _callback's second arg. */ 12 | #define callback(fn, arg) \ 13 | _callback(typesafe_cb(void, (fn), (arg)), (arg)) 14 | 15 | void my_callback(int something); 16 | void my_callback(int something) 17 | { 18 | } 19 | 20 | int main(int argc, char *argv[]) 21 | { 22 | #ifdef FAIL 23 | /* This fails due to arg, not due to cast. */ 24 | callback(my_callback, 100); 25 | #endif 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /ccan/typesafe_cb/test/compile_fail-typesafe_cb_postargs.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static void _register_callback(void (*cb)(void *arg, int x), void *arg) 5 | { 6 | } 7 | #define register_callback(cb, arg) \ 8 | _register_callback(typesafe_cb_postargs(void, void *, (cb), (arg), int), (arg)) 9 | 10 | static void my_callback(char *p, int x) 11 | { 12 | } 13 | 14 | int main(int argc, char *argv[]) 15 | { 16 | #ifdef FAIL 17 | int *p; 18 | #if !HAVE_TYPEOF||!HAVE_BUILTIN_CHOOSE_EXPR||!HAVE_BUILTIN_TYPES_COMPATIBLE_P 19 | #error "Unfortunately we don't fail if typesafe_cb_cast is a noop." 20 | #endif 21 | #else 22 | char *p; 23 | #endif 24 | p = NULL; 25 | register_callback(my_callback, p); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /ccan/typesafe_cb/test/compile_fail-typesafe_cb_preargs.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static void _register_callback(void (*cb)(int x, void *arg), void *arg) 5 | { 6 | } 7 | 8 | #define register_callback(cb, arg) \ 9 | _register_callback(typesafe_cb_preargs(void, void *, (cb), (arg), int), (arg)) 10 | 11 | static void my_callback(int x, char *p) 12 | { 13 | } 14 | 15 | int main(int argc, char *argv[]) 16 | { 17 | #ifdef FAIL 18 | int *p; 19 | #if !HAVE_TYPEOF||!HAVE_BUILTIN_CHOOSE_EXPR||!HAVE_BUILTIN_TYPES_COMPATIBLE_P 20 | #error "Unfortunately we don't fail if typesafe_cb_cast is a noop." 21 | #endif 22 | #else 23 | char *p; 24 | #endif 25 | p = NULL; 26 | register_callback(my_callback, p); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /compat/libusb-1.0/README: -------------------------------------------------------------------------------- 1 | libusb 2 | ====== 3 | 4 | libusb is a library for USB device access from Linux, Mac OS X, 5 | OpenBSD, NetBSD, and Windows userspace. 6 | It is written in C and licensed under the LGPL-2.1 (see COPYING). 7 | 8 | libusb is abstracted internally in such a way that it can hopefully 9 | be ported to other operating systems. See the PORTING file for some 10 | information, if you fancy a challenge. :) 11 | 12 | libusb homepage: 13 | http://libusb.org/ 14 | 15 | Developers will wish to consult the API documentation: 16 | http://libusb.sourceforge.net/api-1.0/ 17 | 18 | Use the mailing list for questions, comments, etc: 19 | http://libusb.org/wiki/MailingList 20 | 21 | - Peter Stuge 22 | (use the mailing list rather than mailing developers directly) 23 | -------------------------------------------------------------------------------- /ccan/typesafe_cb/test/compile_fail-typesafe_cb_cast-multi.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct foo { 5 | int x; 6 | }; 7 | 8 | struct bar { 9 | int x; 10 | }; 11 | 12 | struct baz { 13 | int x; 14 | }; 15 | 16 | struct any { 17 | int x; 18 | }; 19 | 20 | struct other { 21 | int x; 22 | }; 23 | 24 | static void take_any(struct any *any) 25 | { 26 | } 27 | 28 | int main(int argc, char *argv[]) 29 | { 30 | #ifdef FAIL 31 | struct other 32 | #if !HAVE_TYPEOF||!HAVE_BUILTIN_CHOOSE_EXPR||!HAVE_BUILTIN_TYPES_COMPATIBLE_P 33 | #error "Unfortunately we don't fail if typesafe_cb_cast is a noop." 34 | #endif 35 | #else 36 | struct foo 37 | #endif 38 | *arg = NULL; 39 | take_any(typesafe_cb_cast3(struct any *, 40 | struct foo *, struct bar *, struct baz *, 41 | arg)); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /ccan/typesafe_cb/test/compile_fail-typesafe_cb.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static void _register_callback(void (*cb)(void *arg), void *arg) 5 | { 6 | } 7 | 8 | #define register_callback(cb, arg) \ 9 | _register_callback(typesafe_cb(void, void *, (cb), (arg)), (arg)) 10 | 11 | static void my_callback(char *p) 12 | { 13 | } 14 | 15 | int main(int argc, char *argv[]) 16 | { 17 | char str[] = "hello world"; 18 | #ifdef FAIL 19 | int *p; 20 | #if !HAVE_TYPEOF||!HAVE_BUILTIN_CHOOSE_EXPR||!HAVE_BUILTIN_TYPES_COMPATIBLE_P 21 | #error "Unfortunately we don't fail if typesafe_cb_cast is a noop." 22 | #endif 23 | #else 24 | char *p; 25 | #endif 26 | p = NULL; 27 | 28 | /* This should work always. */ 29 | register_callback(my_callback, str); 30 | 31 | /* This will fail with FAIL defined */ 32 | register_callback(my_callback, p); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /ccan/opt/test/run-no-options.c: -------------------------------------------------------------------------------- 1 | /* Make sure we still work with no options registered */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "utils.h" 9 | 10 | int main(int argc, char *argv[]) 11 | { 12 | const char *myname = argv[0]; 13 | 14 | plan_tests(7); 15 | 16 | /* Simple short arg.*/ 17 | ok1(!parse_args(&argc, &argv, "-a", NULL)); 18 | /* Simple long arg.*/ 19 | ok1(!parse_args(&argc, &argv, "--aaa", NULL)); 20 | 21 | /* Extra arguments preserved. */ 22 | ok1(parse_args(&argc, &argv, "extra", "args", NULL)); 23 | ok1(argc == 3); 24 | ok1(argv[0] == myname); 25 | ok1(strcmp(argv[1], "extra") == 0); 26 | ok1(strcmp(argv[2], "args") == 0); 27 | 28 | /* parse_args allocates argv */ 29 | free(argv); 30 | 31 | return exit_status(); 32 | } 33 | 34 | -------------------------------------------------------------------------------- /m4/wchar_t.m4: -------------------------------------------------------------------------------- 1 | # wchar_t.m4 serial 4 (gettext-0.18.2) 2 | dnl Copyright (C) 2002-2003, 2008-2011 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl From Bruno Haible. 8 | dnl Test whether has the 'wchar_t' type. 9 | dnl Prerequisite: AC_PROG_CC 10 | 11 | AC_DEFUN([gt_TYPE_WCHAR_T], 12 | [ 13 | AC_CACHE_CHECK([for wchar_t], [gt_cv_c_wchar_t], 14 | [AC_COMPILE_IFELSE( 15 | [AC_LANG_PROGRAM( 16 | [[#include 17 | wchar_t foo = (wchar_t)'\0';]], 18 | [[]])], 19 | [gt_cv_c_wchar_t=yes], 20 | [gt_cv_c_wchar_t=no])]) 21 | if test $gt_cv_c_wchar_t = yes; then 22 | AC_DEFINE([HAVE_WCHAR_T], [1], [Define if you have the 'wchar_t' type.]) 23 | fi 24 | ]) 25 | -------------------------------------------------------------------------------- /ccan/typesafe_cb/test/compile_ok-typesafe_cb_cast.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct foo { 5 | int x; 6 | }; 7 | 8 | struct bar { 9 | int x; 10 | }; 11 | 12 | struct baz { 13 | int x; 14 | }; 15 | 16 | struct any { 17 | int x; 18 | }; 19 | 20 | static void take_any(struct any *any) 21 | { 22 | } 23 | 24 | int main(int argc, char *argv[]) 25 | { 26 | /* Otherwise we get unused warnings for these. */ 27 | struct foo *foo = NULL; 28 | struct bar *bar = NULL; 29 | struct baz *baz = NULL; 30 | 31 | take_any(typesafe_cb_cast3(struct any *, 32 | struct foo *, struct bar *, struct baz *, 33 | foo)); 34 | take_any(typesafe_cb_cast3(struct any *, 35 | struct foo *, struct bar *, struct baz *, 36 | bar)); 37 | take_any(typesafe_cb_cast3(struct any *, 38 | struct foo *, struct bar *, struct baz *, 39 | baz)); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /mknsis.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | MINGW_PATH=/usr/i686-pc-mingw32/sys-root/mingw/bin 4 | 5 | OUT_BASE="cpuminer-installer" 6 | OUT_EXE="$OUT_BASE.exe" 7 | 8 | PATH=$PATH:$MINGW_PATH \ 9 | nsiswrapper --run \ 10 | --name "CPU miner" \ 11 | --outfile "$OUT_EXE" \ 12 | minerd.exe \ 13 | $MINGW_PATH/libcurl-4.dll=libcurl-4.dll \ 14 | $MINGW_PATH/pthreadgc2.dll=pthreadgc2.dll \ 15 | $MINGW_PATH/libidn-11.dll=libidn-11.dll \ 16 | $MINGW_PATH/libssh2-1.dll=libssh2-1.dll \ 17 | $MINGW_PATH/libssl-10.dll=libssl-10.dll \ 18 | $MINGW_PATH/zlib1.dll=zlib1.dll \ 19 | $MINGW_PATH/libcrypto-10.dll=libcrypto-10.dll \ 20 | $MINGW_PATH/libiconv-2.dll=libiconv-2.dll \ 21 | $MINGW_PATH/libintl-8.dll=libintl-8.dll 22 | 23 | chmod 0755 "$OUT_EXE" 24 | zip -9 "$OUT_BASE" "$OUT_EXE" 25 | rm -f "$OUT_EXE" 26 | 27 | chmod 0644 "$OUT_BASE.zip" 28 | 29 | echo -n "SHA1: " 30 | sha1sum "$OUT_BASE.zip" 31 | 32 | echo -n "MD5: " 33 | md5sum "$OUT_BASE.zip" 34 | 35 | -------------------------------------------------------------------------------- /adl.h: -------------------------------------------------------------------------------- 1 | #ifndef __ADL_H__ 2 | #define __ADL_H__ 3 | #ifdef HAVE_ADL 4 | bool adl_active; 5 | bool opt_reorder; 6 | int opt_hysteresis; 7 | const int opt_targettemp; 8 | const int opt_overheattemp; 9 | void init_adl(int nDevs); 10 | float gpu_temp(int gpu); 11 | int gpu_engineclock(int gpu); 12 | int gpu_memclock(int gpu); 13 | float gpu_vddc(int gpu); 14 | int gpu_activity(int gpu); 15 | int gpu_fanspeed(int gpu); 16 | int gpu_fanpercent(int gpu); 17 | bool gpu_stats(int gpu, float *temp, int *engineclock, int *memclock, float *vddc, 18 | int *activity, int *fanspeed, int *fanpercent, int *powertune); 19 | void change_gpusettings(int gpu); 20 | void gpu_autotune(int gpu, enum dev_enable *denable); 21 | void clear_adl(int nDevs); 22 | #else /* HAVE_ADL */ 23 | #define adl_active (0) 24 | static inline void init_adl(__maybe_unused int nDevs) {} 25 | static inline void change_gpusettings(__maybe_unused int gpu) { } 26 | static inline void clear_adl(__maybe_unused int nDevs) {} 27 | #endif 28 | #endif 29 | -------------------------------------------------------------------------------- /compat/jansson-2.5/src/strbuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2013 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef STRBUFFER_H 9 | #define STRBUFFER_H 10 | 11 | typedef struct { 12 | char *value; 13 | size_t length; /* bytes used */ 14 | size_t size; /* bytes allocated */ 15 | } strbuffer_t; 16 | 17 | int strbuffer_init(strbuffer_t *strbuff); 18 | void strbuffer_close(strbuffer_t *strbuff); 19 | 20 | void strbuffer_clear(strbuffer_t *strbuff); 21 | 22 | const char *strbuffer_value(const strbuffer_t *strbuff); 23 | 24 | /* Steal the value and close the strbuffer */ 25 | char *strbuffer_steal_value(strbuffer_t *strbuff); 26 | 27 | int strbuffer_append(strbuffer_t *strbuff, const char *string); 28 | int strbuffer_append_byte(strbuffer_t *strbuff, char byte); 29 | int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size); 30 | 31 | char strbuffer_pop(strbuffer_t *strbuff); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /bitstreams/COPYING_fpgaminer: -------------------------------------------------------------------------------- 1 | All the bitstream files included in this directory that follow the name pattern fpgaminer_*.ncd are: 2 | 3 | ---- 4 | 5 | Copyright (c) 2011-2012 fpgaminer@bitcoin-mining.com 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | 20 | ---- 21 | 22 | You can find the original sources at the Open Source FPGA Bitcoin Miner project GitHub repository: 23 | https://github.com/progranism/Open-Source-FPGA-Bitcoin-Miner/tree/master/projects/X6000_ztex_comm4/hdl 24 | -------------------------------------------------------------------------------- /driver-opencl.h: -------------------------------------------------------------------------------- 1 | #ifndef __DEVICE_GPU_H__ 2 | #define __DEVICE_GPU_H__ 3 | 4 | #include "miner.h" 5 | 6 | 7 | extern void print_ndevs(int *ndevs); 8 | extern void *reinit_gpu(void *userdata); 9 | extern char *set_gpu_map(char *arg); 10 | extern char *set_gpu_engine(char *arg); 11 | extern char *set_gpu_fan(char *arg); 12 | extern char *set_gpu_memclock(char *arg); 13 | extern char *set_gpu_memdiff(char *arg); 14 | extern char *set_gpu_powertune(char *arg); 15 | extern char *set_gpu_vddc(char *arg); 16 | extern char *set_temp_overheat(char *arg); 17 | extern char *set_temp_target(char *arg); 18 | extern char *set_intensity(char *arg); 19 | extern char *set_vector(char *arg); 20 | extern char *set_worksize(char *arg); 21 | #ifdef USE_SCRYPT 22 | extern char *set_shaders(char *arg); 23 | extern char *set_lookup_gap(char *arg); 24 | extern char *set_thread_concurrency(char *arg); 25 | #endif 26 | extern char *set_kernel(char *arg); 27 | void manage_gpu(void); 28 | extern void pause_dynamic_threads(int gpu); 29 | 30 | extern bool opt_opencl; 31 | extern int opt_platform_id; 32 | 33 | extern struct device_drv opencl_drv; 34 | 35 | #endif /* __DEVICE_GPU_H__ */ 36 | -------------------------------------------------------------------------------- /compat/jansson-2.5/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009-2013 Petri Lehtinen 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /compat/jansson-2.5/src/utf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2013 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef UTF_H 9 | #define UTF_H 10 | 11 | #ifdef HAVE_CONFIG_H 12 | #include 13 | 14 | #ifdef HAVE_INTTYPES_H 15 | /* inttypes.h includes stdint.h in a standard environment, so there's 16 | no need to include stdint.h separately. If inttypes.h doesn't define 17 | int32_t, it's defined in config.h. */ 18 | #include 19 | #endif /* HAVE_INTTYPES_H */ 20 | 21 | #else /* !HAVE_CONFIG_H */ 22 | #ifdef _WIN32 23 | typedef int int32_t; 24 | #else /* !_WIN32 */ 25 | /* Assume a standard environment */ 26 | #include 27 | #endif /* _WIN32 */ 28 | 29 | #endif /* HAVE_CONFIG_H */ 30 | 31 | int utf8_encode(int codepoint, char *buffer, int *size); 32 | 33 | int utf8_check_first(char byte); 34 | int utf8_check_full(const char *buffer, int size, int32_t *codepoint); 35 | const char *utf8_iterate(const char *buffer, int32_t *codepoint); 36 | 37 | int utf8_check_string(const char *string, int length); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /compat/libusb-1.0/AUTHORS: -------------------------------------------------------------------------------- 1 | Copyright (C) 2007-2009 Daniel Drake 2 | Copyright (c) 2001 Johannes Erdfelt 3 | Copyright (C) 2008-2013 Nathan Hjelm 4 | Copyright (C) 2009-2012 Pete Batard 5 | Copyright (C) 2010 Michael Plante 6 | Copyright (C) 2010-2012 Peter Stuge 7 | Copyright (C) 2011-2012 Hans de Goede 8 | Copyright (C) 2012 Martin Pieuchot 9 | 10 | Other contributors: 11 | Alan Ott 12 | Alan Stern 13 | Alex Vatchenko 14 | Artem Egorkine 15 | Aurelien Jarno 16 | Bastien Nocera 17 | Brian Shirley 18 | David Engraf 19 | David Moore 20 | Felipe Balbi 21 | Graeme Gill 22 | Hans de Goede 23 | Hans Ulrich Niedermann 24 | Hector Martin 25 | Hoi-Ho Chan 26 | James Hanko 27 | Konrad Rzepecki 28 | Ludovic Rousseau 29 | Martin Koegler 30 | Martin Pieuchot 31 | Maya Erez 32 | Mike Frysinger 33 | Mikhail Gusarov 34 | Orin Eman 35 | Pekka Nikander 36 | Peter Stuge 37 | Rob Walker 38 | Sean McBride 39 | Sebastian Pipping 40 | Stephan Meyer 41 | Thomas Röfer 42 | Toby Peterson 43 | Trygve Laugstøl 44 | Vasily Khoruzhick 45 | Vitali Lovich 46 | Xiaofan Chen 47 | -------------------------------------------------------------------------------- /arg-nonnull.h: -------------------------------------------------------------------------------- 1 | /* A C macro for declaring that specific arguments must not be NULL. 2 | Copyright (C) 2009-2011 Free Software Foundation, Inc. 3 | 4 | This program is free software: you can redistribute it and/or modify it 5 | under the terms of the GNU General Public License as published 6 | by the Free Software Foundation; either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . */ 16 | 17 | /* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools 18 | that the values passed as arguments n, ..., m must be non-NULL pointers. 19 | n = 1 stands for the first argument, n = 2 for the second argument etc. */ 20 | #ifndef _GL_ARG_NONNULL 21 | # if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3 22 | # define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params)) 23 | # else 24 | # define _GL_ARG_NONNULL(params) 25 | # endif 26 | #endif 27 | -------------------------------------------------------------------------------- /compat/jansson-2.5/src/memory.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2013 Petri Lehtinen 3 | * Copyright (c) 2011-2012 Basile Starynkevitch 4 | * 5 | * Jansson is free software; you can redistribute it and/or modify it 6 | * under the terms of the MIT license. See LICENSE for details. 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | #include "jansson.h" 13 | #include "jansson_private.h" 14 | 15 | /* memory function pointers */ 16 | static json_malloc_t do_malloc = malloc; 17 | static json_free_t do_free = free; 18 | 19 | void *jsonp_malloc(size_t size) 20 | { 21 | if(!size) 22 | return NULL; 23 | 24 | return (*do_malloc)(size); 25 | } 26 | 27 | void jsonp_free(void *ptr) 28 | { 29 | if(!ptr) 30 | return; 31 | 32 | (*do_free)(ptr); 33 | } 34 | 35 | char *jsonp_strdup(const char *str) 36 | { 37 | char *new_str; 38 | size_t len; 39 | 40 | len = strlen(str); 41 | if(len == (size_t)-1) 42 | return NULL; 43 | 44 | new_str = jsonp_malloc(len + 1); 45 | if(!new_str) 46 | return NULL; 47 | 48 | memcpy(new_str, str, len + 1); 49 | return new_str; 50 | } 51 | 52 | void json_set_alloc_funcs(json_malloc_t malloc_fn, json_free_t free_fn) 53 | { 54 | do_malloc = malloc_fn; 55 | do_free = free_fn; 56 | } 57 | -------------------------------------------------------------------------------- /ccan/typesafe_cb/test/compile_ok-typesafe_cb-undefined.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* const args in callbacks should be OK. */ 5 | 6 | static void _register_callback(void (*cb)(void *arg), void *arg) 7 | { 8 | } 9 | 10 | #define register_callback(cb, arg) \ 11 | _register_callback(typesafe_cb(void, void *, (cb), (arg)), (arg)) 12 | 13 | static void _register_callback_pre(void (*cb)(int x, void *arg), void *arg) 14 | { 15 | } 16 | 17 | #define register_callback_pre(cb, arg) \ 18 | _register_callback_pre(typesafe_cb_preargs(void, void *, (cb), (arg), int), (arg)) 19 | 20 | static void _register_callback_post(void (*cb)(void *arg, int x), void *arg) 21 | { 22 | } 23 | 24 | #define register_callback_post(cb, arg) \ 25 | _register_callback_post(typesafe_cb_postargs(void, void *, (cb), (arg), int), (arg)) 26 | 27 | struct undefined; 28 | 29 | static void my_callback(struct undefined *undef) 30 | { 31 | } 32 | 33 | static void my_callback_pre(int x, struct undefined *undef) 34 | { 35 | } 36 | 37 | static void my_callback_post(struct undefined *undef, int x) 38 | { 39 | } 40 | 41 | int main(int argc, char *argv[]) 42 | { 43 | struct undefined *handle = NULL; 44 | 45 | register_callback(my_callback, handle); 46 | register_callback_pre(my_callback_pre, handle); 47 | register_callback_post(my_callback_post, handle); 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /compat/jansson-2.5/src/jansson_config.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2013 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | * 7 | * 8 | * This file specifies a part of the site-specific configuration for 9 | * Jansson, namely those things that affect the public API in 10 | * jansson.h. 11 | * 12 | * The configure script copies this file to jansson_config.h and 13 | * replaces @var@ substitutions by values that fit your system. If you 14 | * cannot run the configure script, you can do the value substitution 15 | * by hand. 16 | */ 17 | 18 | #ifndef JANSSON_CONFIG_H 19 | #define JANSSON_CONFIG_H 20 | 21 | /* If your compiler supports the inline keyword in C, JSON_INLINE is 22 | defined to `inline', otherwise empty. In C++, the inline is always 23 | supported. */ 24 | #ifdef __cplusplus 25 | #define JSON_INLINE inline 26 | #else 27 | #define JSON_INLINE @json_inline@ 28 | #endif 29 | 30 | /* If your compiler supports the `long long` type and the strtoll() 31 | library function, JSON_INTEGER_IS_LONG_LONG is defined to 1, 32 | otherwise to 0. */ 33 | #define JSON_INTEGER_IS_LONG_LONG @json_have_long_long@ 34 | 35 | /* If locale.h and localeconv() are available, define to 1, 36 | otherwise to 0. */ 37 | #define JSON_HAVE_LOCALECONV @json_have_localeconv@ 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /libbitfury.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Con Kolivas 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the Free 6 | * Software Foundation; either version 3 of the License, or (at your option) 7 | * any later version. See COPYING for more details. 8 | */ 9 | 10 | #ifndef LIBBITFURY_H 11 | #define LIBBITFURY_H 12 | #include "miner.h" 13 | #include "driver-bitfury.h" 14 | 15 | void ms3steps(uint32_t *p); 16 | uint32_t decnonce(uint32_t in); 17 | void bitfury_work_to_payload(struct bitfury_payload *p, struct work *work); 18 | void spi_set_freq(struct bitfury_info *info); 19 | void spi_send_conf(struct bitfury_info *info); 20 | void spi_send_init(struct bitfury_info *info); 21 | void spi_clear_buf(struct bitfury_info *info); 22 | void spi_add_buf(struct bitfury_info *info, const void *buf, const int sz); 23 | void spi_add_break(struct bitfury_info *info); 24 | void spi_add_data(struct bitfury_info *info, uint16_t addr, const void *buf, int len); 25 | bool spi_reset(struct cgpu_info *bitfury, struct bitfury_info *info); 26 | bool spi_txrx(struct cgpu_info *bitfury, struct bitfury_info *info); 27 | bool bitfury_checkresults(struct thr_info *thr, struct work *work, uint32_t nonce); 28 | bool libbitfury_sendHashData(struct thr_info *thr, struct cgpu_info *bitfury, 29 | struct bitfury_info *info); 30 | 31 | #endif /* LIBBITFURY_H */ 32 | -------------------------------------------------------------------------------- /m4/sigaction.m4: -------------------------------------------------------------------------------- 1 | # sigaction.m4 serial 6 2 | dnl Copyright (C) 2008-2011 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | # Determine if sigaction interface is present. 8 | AC_DEFUN([gl_SIGACTION], 9 | [ 10 | AC_REQUIRE([gl_SIGNAL_H_DEFAULTS]) 11 | AC_CHECK_FUNCS_ONCE([sigaction]) 12 | if test $ac_cv_func_sigaction = yes; then 13 | AC_CHECK_MEMBERS([struct sigaction.sa_sigaction], , , 14 | [[#include ]]) 15 | if test $ac_cv_member_struct_sigaction_sa_sigaction = no; then 16 | HAVE_STRUCT_SIGACTION_SA_SIGACTION=0 17 | fi 18 | else 19 | HAVE_SIGACTION=0 20 | fi 21 | ]) 22 | 23 | # Prerequisites of the part of lib/signal.in.h and of lib/sigaction.c. 24 | AC_DEFUN([gl_PREREQ_SIGACTION], 25 | [ 26 | AC_REQUIRE([gl_SIGNAL_H_DEFAULTS]) 27 | AC_REQUIRE([AC_C_RESTRICT]) 28 | AC_REQUIRE([AC_TYPE_UID_T]) 29 | AC_REQUIRE([gl_PREREQ_SIG_HANDLER_H]) 30 | AC_CHECK_FUNCS_ONCE([sigaltstack siginterrupt]) 31 | AC_CHECK_TYPES([siginfo_t], [], [], [[ 32 | #include 33 | ]]) 34 | if test $ac_cv_type_siginfo_t = no; then 35 | HAVE_SIGINFO_T=0 36 | fi 37 | ]) 38 | 39 | # Prerequisites of lib/sig-handler.h. 40 | AC_DEFUN([gl_PREREQ_SIG_HANDLER_H], 41 | [ 42 | AC_REQUIRE([AC_C_INLINE]) 43 | ]) 44 | -------------------------------------------------------------------------------- /compat/jansson-2.5/configure.ac: -------------------------------------------------------------------------------- 1 | AC_PREREQ([2.60]) 2 | AC_INIT([jansson], [2.5], [petri@digip.org]) 3 | 4 | AC_CONFIG_MACRO_DIR([m4]) 5 | 6 | AM_INIT_AUTOMAKE([1.10 foreign]) 7 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) 8 | 9 | AC_CONFIG_SRCDIR([src/value.c]) 10 | AC_CONFIG_HEADERS([config.h]) 11 | 12 | # Checks for programs. 13 | AC_PROG_CC 14 | AC_PROG_LIBTOOL 15 | AM_CONDITIONAL([GCC], [test x$GCC = xyes]) 16 | 17 | # Checks for libraries. 18 | 19 | # Checks for header files. 20 | AC_CHECK_HEADERS([locale.h]) 21 | 22 | # Checks for typedefs, structures, and compiler characteristics. 23 | AC_TYPE_INT32_T 24 | AC_TYPE_LONG_LONG_INT 25 | 26 | AC_C_INLINE 27 | case $ac_cv_c_inline in 28 | yes) json_inline=inline;; 29 | no) json_inline=;; 30 | *) json_inline=$ac_cv_c_inline;; 31 | esac 32 | AC_SUBST([json_inline]) 33 | 34 | # Checks for library functions. 35 | AC_CHECK_FUNCS([strtoll localeconv]) 36 | 37 | case "$ac_cv_type_long_long_int$ac_cv_func_strtoll" in 38 | yesyes) json_have_long_long=1;; 39 | *) json_have_long_long=0;; 40 | esac 41 | AC_SUBST([json_have_long_long]) 42 | 43 | case "$ac_cv_header_locale_h$ac_cv_func_localeconv" in 44 | yesyes) json_have_localeconv=1;; 45 | *) json_have_localeconv=0;; 46 | esac 47 | AC_SUBST([json_have_localeconv]) 48 | 49 | AC_CONFIG_FILES([ 50 | jansson.pc 51 | Makefile 52 | src/Makefile 53 | src/jansson_config.h 54 | ]) 55 | AC_OUTPUT 56 | -------------------------------------------------------------------------------- /m4/00gnulib.m4: -------------------------------------------------------------------------------- 1 | # 00gnulib.m4 serial 2 2 | dnl Copyright (C) 2009-2011 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl This file must be named something that sorts before all other 8 | dnl gnulib-provided .m4 files. It is needed until such time as we can 9 | dnl assume Autoconf 2.64, with its improved AC_DEFUN_ONCE semantics. 10 | 11 | # AC_DEFUN_ONCE([NAME], VALUE) 12 | # ---------------------------- 13 | # Define NAME to expand to VALUE on the first use (whether by direct 14 | # expansion, or by AC_REQUIRE), and to nothing on all subsequent uses. 15 | # Avoid bugs in AC_REQUIRE in Autoconf 2.63 and earlier. This 16 | # definition is slower than the version in Autoconf 2.64, because it 17 | # can only use interfaces that existed since 2.59; but it achieves the 18 | # same effect. Quoting is necessary to avoid confusing Automake. 19 | m4_version_prereq([2.63.263], [], 20 | [m4_define([AC][_DEFUN_ONCE], 21 | [AC][_DEFUN([$1], 22 | [AC_REQUIRE([_gl_DEFUN_ONCE([$1])], 23 | [m4_indir([_gl_DEFUN_ONCE([$1])])])])]dnl 24 | [AC][_DEFUN([_gl_DEFUN_ONCE([$1])], [$2])])]) 25 | 26 | # gl_00GNULIB 27 | # ----------- 28 | # Witness macro that this file has been included. Needed to force 29 | # Automake to include this file prior to all other gnulib .m4 files. 30 | AC_DEFUN([gl_00GNULIB]) 31 | -------------------------------------------------------------------------------- /ocl.h: -------------------------------------------------------------------------------- 1 | #ifndef __OCL_H__ 2 | #define __OCL_H__ 3 | 4 | #include "config.h" 5 | 6 | #include 7 | #define MAXTHREADS (0xFFFFFFFEULL) 8 | #define MAXBUFFERS (0x10) 9 | #define BUFFERSIZE (sizeof(uint32_t) * MAXBUFFERS) 10 | #define FOUND (0x0F) 11 | 12 | #define SCRYPT_MAXBUFFERS (0x100) 13 | #define SCRYPT_BUFFERSIZE (sizeof(uint32_t) * SCRYPT_MAXBUFFERS) 14 | #define SCRYPT_FOUND (0xFF) 15 | 16 | #ifdef HAVE_OPENCL 17 | #ifdef __APPLE_CC__ 18 | #include 19 | #else 20 | #include 21 | #endif 22 | 23 | #include "miner.h" 24 | 25 | typedef struct { 26 | cl_context context; 27 | cl_kernel kernel; 28 | cl_command_queue commandQueue; 29 | cl_program program; 30 | cl_mem outputBuffer; 31 | #ifdef USE_SCRYPT 32 | cl_mem CLbuffer0; 33 | cl_mem padbuffer8; 34 | size_t padbufsize; 35 | void * cldata; 36 | #endif 37 | bool hasBitAlign; 38 | bool hasOpenCL11plus; 39 | bool hasOpenCL12plus; 40 | bool goffset; 41 | cl_uint vwidth; 42 | size_t max_work_size; 43 | size_t wsize; 44 | enum cl_kernels chosen_kernel; 45 | } _clState; 46 | 47 | extern char *file_contents(const char *filename, int *length); 48 | extern int clDevicesNum(void); 49 | extern _clState *initCl(unsigned int gpu, char *name, size_t nameSize); 50 | 51 | extern void precalc_hash(dev_blk_ctx *blk, uint32_t *state, uint32_t *data); 52 | extern void postcalc_hash_async(struct thr_info *thr, struct work *work, uint32_t *res); 53 | 54 | #endif /* HAVE_OPENCL */ 55 | #endif /* __OCL_H__ */ 56 | -------------------------------------------------------------------------------- /m4/gnulib-cache.m4: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2002-2011 Free Software Foundation, Inc. 2 | # 3 | # This file is free software, distributed under the terms of the GNU 4 | # General Public License. As a special exception to the GNU General 5 | # Public License, this file may be distributed as part of a program 6 | # that contains a configuration script generated by Autoconf, under 7 | # the same distribution terms as the rest of that program. 8 | # 9 | # Generated by gnulib-tool. 10 | # 11 | # This file represents the specification of how gnulib-tool is used. 12 | # It acts as a cache: It is written and read by gnulib-tool. 13 | # In projects that use version control, this file is meant to be put under 14 | # version control, like the configure.ac and various Makefile.am files. 15 | 16 | 17 | # Specification in the form of a command-line invocation: 18 | # gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files memmem sigaction signal 19 | 20 | # Specification in the form of a few gnulib-tool.m4 macro invocations: 21 | gl_LOCAL_DIR([]) 22 | gl_MODULES([ 23 | memmem 24 | sigaction 25 | signal 26 | ]) 27 | gl_AVOID([]) 28 | gl_SOURCE_BASE([lib]) 29 | gl_M4_BASE([m4]) 30 | gl_PO_BASE([]) 31 | gl_DOC_BASE([doc]) 32 | gl_TESTS_BASE([tests]) 33 | gl_LIB([libgnu]) 34 | gl_MAKEFILE_NAME([]) 35 | gl_MACRO_PREFIX([gl]) 36 | gl_PO_DOMAIN([]) 37 | gl_WITNESS_C_DOMAIN([]) 38 | gl_VC_FILES([false]) 39 | -------------------------------------------------------------------------------- /ccan/typesafe_cb/test/compile_ok-typesafe_cb-vars.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* const args in callbacks should be OK. */ 5 | 6 | static void _register_callback(void (*cb)(void *arg), void *arg) 7 | { 8 | } 9 | 10 | #define register_callback(cb, arg) \ 11 | _register_callback(typesafe_cb(void, void *, (cb), (arg)), (arg)) 12 | 13 | static void _register_callback_pre(void (*cb)(int x, void *arg), void *arg) 14 | { 15 | } 16 | 17 | #define register_callback_pre(cb, arg) \ 18 | _register_callback_pre(typesafe_cb_preargs(void, void *, (cb), (arg), int), (arg)) 19 | 20 | static void _register_callback_post(void (*cb)(void *arg, int x), void *arg) 21 | { 22 | } 23 | 24 | #define register_callback_post(cb, arg) \ 25 | _register_callback_post(typesafe_cb_postargs(void, void *, (cb), (arg), int), (arg)) 26 | 27 | struct undefined; 28 | 29 | static void my_callback(struct undefined *undef) 30 | { 31 | } 32 | 33 | static void my_callback_pre(int x, struct undefined *undef) 34 | { 35 | } 36 | 37 | static void my_callback_post(struct undefined *undef, int x) 38 | { 39 | } 40 | 41 | int main(int argc, char *argv[]) 42 | { 43 | struct undefined *handle = NULL; 44 | void (*cb)(struct undefined *undef) = my_callback; 45 | void (*pre)(int x, struct undefined *undef) = my_callback_pre; 46 | void (*post)(struct undefined *undef, int x) = my_callback_post; 47 | 48 | register_callback(cb, handle); 49 | register_callback_pre(pre, handle); 50 | register_callback_post(post, handle); 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /driver-drillbit.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Con Kolivas 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the Free 6 | * Software Foundation; either version 3 of the License, or (at your option) 7 | * any later version. See COPYING for more details. 8 | */ 9 | 10 | #ifndef BITFURY_H 11 | #define BITFURY_H 12 | 13 | #include "miner.h" 14 | #include "usbutils.h" 15 | 16 | #define WORK_HISTORY_LEN 4 17 | 18 | struct drillbit_chip_info; 19 | 20 | /* drillbit_info structure applies to entire device */ 21 | struct drillbit_info { 22 | struct cgpu_info *base_cgpu; 23 | uint8_t version; 24 | uint8_t num_chips; 25 | uint16_t capabilities; 26 | char product[8]; 27 | uint32_t serial; 28 | struct drillbit_chip_info *chips; 29 | struct timeval tv_lastchipinfo; 30 | struct timeval tv_lasttemp; 31 | uint16_t temp; 32 | uint16_t max_temp; 33 | }; 34 | 35 | enum drillbit_chip_state { 36 | IDLE, /* Has no work */ 37 | WORKING_NOQUEUED, /* Has current work but nothing queued as "next work" */ 38 | WORKING_QUEUED /* Has current work and a piece of work queued for after that */ 39 | }; 40 | 41 | struct drillbit_chip_info { 42 | uint16_t chip_id; 43 | struct work *current_work[WORK_HISTORY_LEN]; 44 | enum drillbit_chip_state state; 45 | struct timeval tv_start; 46 | uint32_t success_count; 47 | uint32_t error_count; 48 | uint32_t timeout_count; 49 | uint32_t work_sent_count; 50 | }; 51 | 52 | #endif /* BITFURY_H */ 53 | -------------------------------------------------------------------------------- /api-example.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python2.7 2 | 3 | # Copyright 2013 Setkeh Mkfr 4 | # 5 | # This program is free software; you can redistribute it and/or modify it under 6 | # the terms of the GNU General Public License as published by the Free Software 7 | # Foundation; either version 3 of the License, or (at your option) any later 8 | # version. See COPYING for more details. 9 | 10 | #Short Python Example for connecting to The Cgminer API 11 | #Written By: setkeh 12 | #Thanks to Jezzz for all his Support. 13 | #NOTE: When adding a param with a pipe | in bash or ZSH you must wrap the arg in quotes 14 | #E.G "pga|0" 15 | 16 | import socket 17 | import json 18 | import sys 19 | 20 | def linesplit(socket): 21 | buffer = socket.recv(4096) 22 | done = False 23 | while not done: 24 | more = socket.recv(4096) 25 | if not more: 26 | done = True 27 | else: 28 | buffer = buffer+more 29 | if buffer: 30 | return buffer 31 | 32 | api_command = sys.argv[1].split('|') 33 | 34 | if len(sys.argv) < 3: 35 | api_ip = '127.0.0.1' 36 | api_port = 4028 37 | else: 38 | api_ip = sys.argv[2] 39 | api_port = sys.argv[3] 40 | 41 | s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) 42 | s.connect((api_ip,int(api_port))) 43 | if len(api_command) == 2: 44 | s.send(json.dumps({"command":api_command[0],"parameter":api_command[1]})) 45 | else: 46 | s.send(json.dumps({"command":api_command[0]})) 47 | 48 | response = linesplit(s) 49 | response = response.replace('\x00','') 50 | response = json.loads(response) 51 | print response 52 | s.close() 53 | -------------------------------------------------------------------------------- /compat/jansson-2.5/src/jansson.def: -------------------------------------------------------------------------------- 1 | EXPORTS 2 | json_delete 3 | json_true 4 | json_false 5 | json_null 6 | json_string 7 | json_string_nocheck 8 | json_string_value 9 | json_string_set 10 | json_string_set_nocheck 11 | json_integer 12 | json_integer_value 13 | json_integer_set 14 | json_real 15 | json_real_value 16 | json_real_set 17 | json_number_value 18 | json_array 19 | json_array_size 20 | json_array_get 21 | json_array_set_new 22 | json_array_append_new 23 | json_array_insert_new 24 | json_array_remove 25 | json_array_clear 26 | json_array_extend 27 | json_object 28 | json_object_size 29 | json_object_get 30 | json_object_set_new 31 | json_object_set_new_nocheck 32 | json_object_del 33 | json_object_clear 34 | json_object_update 35 | json_object_update_existing 36 | json_object_update_missing 37 | json_object_iter 38 | json_object_iter_at 39 | json_object_iter_next 40 | json_object_iter_key 41 | json_object_iter_value 42 | json_object_iter_set_new 43 | json_object_key_to_iter 44 | json_dumps 45 | json_dumpf 46 | json_dump_file 47 | json_dump_callback 48 | json_loads 49 | json_loadb 50 | json_loadf 51 | json_load_file 52 | json_load_callback 53 | json_equal 54 | json_copy 55 | json_deep_copy 56 | json_pack 57 | json_pack_ex 58 | json_vpack_ex 59 | json_unpack 60 | json_unpack_ex 61 | json_vunpack_ex 62 | json_set_alloc_funcs 63 | 64 | -------------------------------------------------------------------------------- /m4/signalblocking.m4: -------------------------------------------------------------------------------- 1 | # signalblocking.m4 serial 11 2 | dnl Copyright (C) 2001-2002, 2006-2011 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | # Determine available signal blocking primitives. Three different APIs exist: 8 | # 1) POSIX: sigemptyset, sigaddset, sigprocmask 9 | # 2) SYSV: sighold, sigrelse 10 | # 3) BSD: sigblock, sigsetmask 11 | # For simplicity, here we check only for the POSIX signal blocking. 12 | AC_DEFUN([gl_SIGNALBLOCKING], 13 | [ 14 | AC_REQUIRE([gl_SIGNAL_H_DEFAULTS]) 15 | signals_not_posix= 16 | AC_EGREP_HEADER([sigset_t], [signal.h], , [signals_not_posix=1]) 17 | if test -z "$signals_not_posix"; then 18 | AC_CHECK_FUNC([sigprocmask], [gl_cv_func_sigprocmask=1]) 19 | fi 20 | if test -z "$gl_cv_func_sigprocmask"; then 21 | HAVE_POSIX_SIGNALBLOCKING=0 22 | fi 23 | ]) 24 | 25 | # Prerequisites of the part of lib/signal.in.h and of lib/sigprocmask.c. 26 | AC_DEFUN([gl_PREREQ_SIGPROCMASK], 27 | [ 28 | AC_REQUIRE([gl_SIGNAL_H_DEFAULTS]) 29 | AC_CHECK_TYPES([sigset_t], 30 | [gl_cv_type_sigset_t=yes], [gl_cv_type_sigset_t=no], 31 | [#include 32 | /* Mingw defines sigset_t not in , but in . */ 33 | #include ]) 34 | if test $gl_cv_type_sigset_t != yes; then 35 | HAVE_SIGSET_T=0 36 | fi 37 | dnl HAVE_SIGSET_T is 1 if the system lacks the sigprocmask function but has 38 | dnl the sigset_t type. 39 | AC_SUBST([HAVE_SIGSET_T]) 40 | ]) 41 | -------------------------------------------------------------------------------- /ccan/opt/test/run-correct-reporting.c: -------------------------------------------------------------------------------- 1 | /* Make sure when multiple equivalent options, correct one is used for errors */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "utils.h" 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | plan_tests(12); 14 | 15 | /* --aaa without args. */ 16 | opt_register_arg("-a|--aaa", test_arg, NULL, "aaa", ""); 17 | ok1(!parse_args(&argc, &argv, "--aaa", NULL)); 18 | ok1(strstr(err_output, ": --aaa: requires an argument")); 19 | free(err_output); 20 | err_output = NULL; 21 | ok1(!parse_args(&argc, &argv, "-a", NULL)); 22 | ok1(strstr(err_output, ": -a: requires an argument")); 23 | free(err_output); 24 | err_output = NULL; 25 | 26 | /* Multiple */ 27 | opt_register_arg("--bbb|-b|-c|--ccc", test_arg, NULL, "aaa", ""); 28 | ok1(!parse_args(&argc, &argv, "--bbb", NULL)); 29 | ok1(strstr(err_output, ": --bbb: requires an argument")); 30 | free(err_output); 31 | err_output = NULL; 32 | ok1(!parse_args(&argc, &argv, "-b", NULL)); 33 | ok1(strstr(err_output, ": -b: requires an argument")); 34 | free(err_output); 35 | err_output = NULL; 36 | ok1(!parse_args(&argc, &argv, "-c", NULL)); 37 | ok1(strstr(err_output, ": -c: requires an argument")); 38 | free(err_output); 39 | err_output = NULL; 40 | ok1(!parse_args(&argc, &argv, "--ccc", NULL)); 41 | ok1(strstr(err_output, ": --ccc: requires an argument")); 42 | free(err_output); 43 | err_output = NULL; 44 | 45 | /* parse_args allocates argv */ 46 | free(argv); 47 | return exit_status(); 48 | } 49 | 50 | -------------------------------------------------------------------------------- /compat/libusb-1.0/libusb/Makefile.am: -------------------------------------------------------------------------------- 1 | lib_LTLIBRARIES = libusb-1.0.la 2 | 3 | LINUX_USBFS_SRC = os/linux_usbfs.c 4 | DARWIN_USB_SRC = os/darwin_usb.c 5 | OPENBSD_USB_SRC = os/openbsd_usb.c 6 | WINDOWS_USB_SRC = os/poll_windows.c os/windows_usb.c libusb-1.0.rc \ 7 | libusb-1.0.def 8 | 9 | EXTRA_DIST = $(LINUX_USBFS_SRC) $(DARWIN_USB_SRC) $(OPENBSD_USB_SRC) \ 10 | $(WINDOWS_USB_SRC) os/threads_posix.c os/threads_windows.c \ 11 | os/linux_udev.c os/linux_netlink.c 12 | 13 | if OS_LINUX 14 | 15 | if USE_UDEV 16 | OS_SRC = $(LINUX_USBFS_SRC) os/linux_udev.c 17 | else 18 | OS_SRC = $(LINUX_USBFS_SRC) os/linux_netlink.c 19 | endif 20 | 21 | endif 22 | 23 | if OS_DARWIN 24 | OS_SRC = $(DARWIN_USB_SRC) 25 | AM_CFLAGS_EXT = -no-cpp-precomp 26 | endif 27 | 28 | if OS_OPENBSD 29 | OS_SRC = $(OPENBSD_USB_SRC) 30 | endif 31 | 32 | if OS_WINDOWS 33 | OS_SRC = $(WINDOWS_USB_SRC) 34 | 35 | .rc.lo: 36 | $(AM_V_GEN)$(LIBTOOL) $(AM_V_lt) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --tag=RC --mode=compile $(RC) $(RCFLAGS) -i $< -o $@ 37 | 38 | libusb-1.0.rc: version.h 39 | endif 40 | 41 | if THREADS_POSIX 42 | THREADS_SRC = os/threads_posix.h os/threads_posix.c 43 | else 44 | THREADS_SRC = os/threads_windows.h os/threads_windows.c 45 | endif 46 | 47 | libusb_1_0_la_CFLAGS = $(AM_CFLAGS) \ 48 | -DLIBUSB_DESCRIBE=\"`git --git-dir "$(top_srcdir)/.git" describe --tags 2>/dev/null`\" 49 | libusb_1_0_la_LDFLAGS = $(LTLDFLAGS) 50 | libusb_1_0_la_SOURCES = libusbi.h core.c descriptor.c io.c sync.c $(OS_SRC) \ 51 | hotplug.h hotplug.c os/linux_usbfs.h os/darwin_usb.h os/windows_usb.h \ 52 | $(THREADS_SRC) os/poll_posix.h os/poll_windows.h 53 | 54 | hdrdir = $(includedir)/libusb-1.0 55 | hdr_HEADERS = libusb.h 56 | -------------------------------------------------------------------------------- /m4/gnulib-tool.m4: -------------------------------------------------------------------------------- 1 | # gnulib-tool.m4 serial 2 2 | dnl Copyright (C) 2004-2005, 2009-2011 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl The following macros need not be invoked explicitly. 8 | dnl Invoking them does nothing except to declare default arguments 9 | dnl for "gnulib-tool --import". 10 | 11 | dnl Usage: gl_LOCAL_DIR([DIR]) 12 | AC_DEFUN([gl_LOCAL_DIR], []) 13 | 14 | dnl Usage: gl_MODULES([module1 module2 ...]) 15 | AC_DEFUN([gl_MODULES], []) 16 | 17 | dnl Usage: gl_AVOID([module1 module2 ...]) 18 | AC_DEFUN([gl_AVOID], []) 19 | 20 | dnl Usage: gl_SOURCE_BASE([DIR]) 21 | AC_DEFUN([gl_SOURCE_BASE], []) 22 | 23 | dnl Usage: gl_M4_BASE([DIR]) 24 | AC_DEFUN([gl_M4_BASE], []) 25 | 26 | dnl Usage: gl_PO_BASE([DIR]) 27 | AC_DEFUN([gl_PO_BASE], []) 28 | 29 | dnl Usage: gl_DOC_BASE([DIR]) 30 | AC_DEFUN([gl_DOC_BASE], []) 31 | 32 | dnl Usage: gl_TESTS_BASE([DIR]) 33 | AC_DEFUN([gl_TESTS_BASE], []) 34 | 35 | dnl Usage: gl_WITH_TESTS 36 | AC_DEFUN([gl_WITH_TESTS], []) 37 | 38 | dnl Usage: gl_LIB([LIBNAME]) 39 | AC_DEFUN([gl_LIB], []) 40 | 41 | dnl Usage: gl_LGPL or gl_LGPL([VERSION]) 42 | AC_DEFUN([gl_LGPL], []) 43 | 44 | dnl Usage: gl_MAKEFILE_NAME([FILENAME]) 45 | AC_DEFUN([gl_MAKEFILE_NAME], []) 46 | 47 | dnl Usage: gl_LIBTOOL 48 | AC_DEFUN([gl_LIBTOOL], []) 49 | 50 | dnl Usage: gl_MACRO_PREFIX([PREFIX]) 51 | AC_DEFUN([gl_MACRO_PREFIX], []) 52 | 53 | dnl Usage: gl_PO_DOMAIN([DOMAIN]) 54 | AC_DEFUN([gl_PO_DOMAIN], []) 55 | 56 | dnl Usage: gl_VC_FILES([BOOLEAN]) 57 | AC_DEFUN([gl_VC_FILES], []) 58 | -------------------------------------------------------------------------------- /m4/stddef_h.m4: -------------------------------------------------------------------------------- 1 | dnl A placeholder for POSIX 2008 , for platforms that have issues. 2 | # stddef_h.m4 serial 4 3 | dnl Copyright (C) 2009-2011 Free Software Foundation, Inc. 4 | dnl This file is free software; the Free Software Foundation 5 | dnl gives unlimited permission to copy and/or distribute it, 6 | dnl with or without modifications, as long as this notice is preserved. 7 | 8 | AC_DEFUN([gl_STDDEF_H], 9 | [ 10 | AC_REQUIRE([gl_STDDEF_H_DEFAULTS]) 11 | AC_REQUIRE([gt_TYPE_WCHAR_T]) 12 | STDDEF_H= 13 | if test $gt_cv_c_wchar_t = no; then 14 | HAVE_WCHAR_T=0 15 | STDDEF_H=stddef.h 16 | fi 17 | AC_CACHE_CHECK([whether NULL can be used in arbitrary expressions], 18 | [gl_cv_decl_null_works], 19 | [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include 20 | int test[2 * (sizeof NULL == sizeof (void *)) -1]; 21 | ]])], 22 | [gl_cv_decl_null_works=yes], 23 | [gl_cv_decl_null_works=no])]) 24 | if test $gl_cv_decl_null_works = no; then 25 | REPLACE_NULL=1 26 | STDDEF_H=stddef.h 27 | fi 28 | AC_SUBST([STDDEF_H]) 29 | AM_CONDITIONAL([GL_GENERATE_STDDEF_H], [test -n "$STDDEF_H"]) 30 | if test -n "$STDDEF_H"; then 31 | gl_NEXT_HEADERS([stddef.h]) 32 | fi 33 | ]) 34 | 35 | AC_DEFUN([gl_STDDEF_MODULE_INDICATOR], 36 | [ 37 | dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 38 | AC_REQUIRE([gl_STDDEF_H_DEFAULTS]) 39 | gl_MODULE_INDICATOR_SET_VARIABLE([$1]) 40 | ]) 41 | 42 | AC_DEFUN([gl_STDDEF_H_DEFAULTS], 43 | [ 44 | dnl Assume proper GNU behavior unless another module says otherwise. 45 | REPLACE_NULL=0; AC_SUBST([REPLACE_NULL]) 46 | HAVE_WCHAR_T=1; AC_SUBST([HAVE_WCHAR_T]) 47 | ]) 48 | -------------------------------------------------------------------------------- /compat/jansson-2.5/README.rst: -------------------------------------------------------------------------------- 1 | Jansson README 2 | ============== 3 | 4 | .. image:: https://travis-ci.org/akheron/jansson.png 5 | :alt: Build status 6 | :target: https://travis-ci.org/akheron/jansson 7 | 8 | Jansson_ is a C library for encoding, decoding and manipulating JSON 9 | data. Its main features and design principles are: 10 | 11 | - Simple and intuitive API and data model 12 | 13 | - Comprehensive documentation 14 | 15 | - No dependencies on other libraries 16 | 17 | - Full Unicode support (UTF-8) 18 | 19 | - Extensive test suite 20 | 21 | Jansson is licensed under the `MIT license`_; see LICENSE in the 22 | source distribution for details. 23 | 24 | 25 | Compilation and Installation 26 | ---------------------------- 27 | 28 | If you obtained a source tarball, just use the standard autotools 29 | commands:: 30 | 31 | $ ./configure 32 | $ make 33 | $ make install 34 | 35 | To run the test suite, invoke:: 36 | 37 | $ make check 38 | 39 | If the source has been checked out from a Git repository, the 40 | ./configure script has to be generated first. The easiest way is to 41 | use autoreconf:: 42 | 43 | $ autoreconf -i 44 | 45 | 46 | Documentation 47 | ------------- 48 | 49 | Prebuilt HTML documentation is available at 50 | http://www.digip.org/jansson/doc/. 51 | 52 | The documentation source is in the ``doc/`` subdirectory. To generate 53 | HTML documentation, invoke:: 54 | 55 | $ make html 56 | 57 | Then, point your browser to ``doc/_build/html/index.html``. Sphinx_ 58 | 1.0 or newer is required to generate the documentation. 59 | 60 | 61 | .. _Jansson: http://www.digip.org/jansson/ 62 | .. _`MIT license`: http://www.opensource.org/licenses/mit-license.php 63 | .. _Sphinx: http://sphinx.pocoo.org/ 64 | -------------------------------------------------------------------------------- /compat/jansson-2.5/src/error.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "jansson_private.h" 3 | 4 | void jsonp_error_init(json_error_t *error, const char *source) 5 | { 6 | if(error) 7 | { 8 | error->text[0] = '\0'; 9 | error->line = -1; 10 | error->column = -1; 11 | error->position = 0; 12 | if(source) 13 | jsonp_error_set_source(error, source); 14 | else 15 | error->source[0] = '\0'; 16 | } 17 | } 18 | 19 | void jsonp_error_set_source(json_error_t *error, const char *source) 20 | { 21 | size_t length; 22 | 23 | if(!error || !source) 24 | return; 25 | 26 | length = strlen(source); 27 | if(length < JSON_ERROR_SOURCE_LENGTH) 28 | strcpy(error->source, source); 29 | else { 30 | size_t extra = length - JSON_ERROR_SOURCE_LENGTH + 4; 31 | strcpy(error->source, "..."); 32 | strcpy(error->source + 3, source + extra); 33 | } 34 | } 35 | 36 | void jsonp_error_set(json_error_t *error, int line, int column, 37 | size_t position, const char *msg, ...) 38 | { 39 | va_list ap; 40 | 41 | va_start(ap, msg); 42 | jsonp_error_vset(error, line, column, position, msg, ap); 43 | va_end(ap); 44 | } 45 | 46 | void jsonp_error_vset(json_error_t *error, int line, int column, 47 | size_t position, const char *msg, va_list ap) 48 | { 49 | if(!error) 50 | return; 51 | 52 | if(error->text[0] != '\0') { 53 | /* error already set */ 54 | return; 55 | } 56 | 57 | error->line = line; 58 | error->column = column; 59 | error->position = position; 60 | 61 | vsnprintf(error->text, JSON_ERROR_TEXT_LENGTH, msg, ap); 62 | error->text[JSON_ERROR_TEXT_LENGTH - 1] = '\0'; 63 | } 64 | -------------------------------------------------------------------------------- /ccan/compiler/_info: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "config.h" 4 | 5 | /** 6 | * compiler - macros for common compiler extensions 7 | * 8 | * Abstracts away some compiler hints. Currently these include: 9 | * - COLD 10 | * For functions not called in fast paths (aka. cold functions) 11 | * - PRINTF_FMT 12 | * For functions which take printf-style parameters. 13 | * - IDEMPOTENT 14 | * For functions which return the same value for same parameters. 15 | * - NEEDED 16 | * For functions and variables which must be emitted even if unused. 17 | * - UNNEEDED 18 | * For functions and variables which need not be emitted if unused. 19 | * - UNUSED 20 | * For parameters which are not used. 21 | * - IS_COMPILE_CONSTANT 22 | * For using different tradeoffs for compiletime vs runtime evaluation. 23 | * 24 | * License: LGPL (3 or any later version) 25 | * Author: Rusty Russell 26 | * 27 | * Example: 28 | * #include 29 | * #include 30 | * #include 31 | * 32 | * // Example of a (slow-path) logging function. 33 | * static int log_threshold = 2; 34 | * static void COLD PRINTF_FMT(2,3) 35 | * logger(int level, const char *fmt, ...) 36 | * { 37 | * va_list ap; 38 | * va_start(ap, fmt); 39 | * if (level >= log_threshold) 40 | * vfprintf(stderr, fmt, ap); 41 | * va_end(ap); 42 | * } 43 | * 44 | * int main(int argc, char *argv[]) 45 | * { 46 | * if (argc != 1) { 47 | * logger(3, "Don't want %i arguments!\n", argc-1); 48 | * return 1; 49 | * } 50 | * return 0; 51 | * } 52 | */ 53 | int main(int argc, char *argv[]) 54 | { 55 | /* Expect exactly one argument */ 56 | if (argc != 2) 57 | return 1; 58 | 59 | if (strcmp(argv[1], "depends") == 0) { 60 | return 0; 61 | } 62 | 63 | return 1; 64 | } 65 | -------------------------------------------------------------------------------- /compat/libusb-1.0/libusb/os/threads_posix.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libusb synchronization using POSIX Threads 3 | * 4 | * Copyright (C) 2011 Vitali Lovich 5 | * Copyright (C) 2011 Peter Stuge 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifdef _XOPEN_SOURCE 23 | # if _XOPEN_SOURCE < 500 24 | # undef _XOPEN_SOURCE 25 | # define _XOPEN_SOURCE 500 26 | # endif 27 | #else 28 | #define _XOPEN_SOURCE 500 29 | #endif /* _XOPEN_SOURCE */ 30 | 31 | #include "threads_posix.h" 32 | 33 | int usbi_mutex_init_recursive(pthread_mutex_t *mutex, pthread_mutexattr_t *attr) 34 | { 35 | int err; 36 | pthread_mutexattr_t stack_attr; 37 | if (!attr) { 38 | attr = &stack_attr; 39 | err = pthread_mutexattr_init(&stack_attr); 40 | if (err != 0) 41 | return err; 42 | } 43 | 44 | err = pthread_mutexattr_settype(attr, PTHREAD_MUTEX_RECURSIVE); 45 | if (err != 0) 46 | goto finish; 47 | 48 | err = pthread_mutex_init(mutex, attr); 49 | 50 | finish: 51 | if (attr == &stack_attr) 52 | pthread_mutexattr_destroy(&stack_attr); 53 | 54 | return err; 55 | } 56 | -------------------------------------------------------------------------------- /compat/libusb-1.0/NEWS: -------------------------------------------------------------------------------- 1 | This file lists notable changes in each release. For the full history of all 2 | changes, see ChangeLog. 3 | 4 | 2012-04-20: 1.0.9 5 | * Numerous bug fixes and improvements 6 | * Backend for Windows, for devices using the WinUSB.sys driver 7 | * Backend for OpenBSD and NetBSD, for devices using the ugen driver 8 | * Add libusb_get_device_speed() 9 | * Add libusb_has_capability() 10 | * Add libusb_error_name() 11 | * Add libusb_get_version() 12 | 13 | 2010-05-07: v1.0.8 14 | * Bug fixes 15 | 16 | 2010-04-19: v1.0.7 17 | * Bug fixes and documentation tweaks 18 | * Add more interface class definitions 19 | 20 | 2009-11-22: v1.0.6 21 | * Bug fixes 22 | * Increase libusb_handle_events() timeout to 60s for powersaving 23 | 24 | 2009-11-15: v1.0.5 25 | * Use timerfd when available for timer management 26 | * Small fixes/updates 27 | 28 | 2009-11-06: v1.0.4 release 29 | * Bug fixes including transfer locking to fix some potential threading races 30 | * More flexibility with clock types on Linux 31 | * Use new bulk continuation tracking in Linux 2.6.32 for improved handling 32 | of short/failed transfers 33 | 34 | 2009-08-27: v1.0.3 release 35 | * Bug fixes 36 | * Add libusb_get_max_iso_packet_size() 37 | 38 | 2009-06-13: v1.0.2 release 39 | * Bug fixes 40 | 41 | 2009-05-12: v1.0.1 release 42 | * Bug fixes 43 | * Darwin backend 44 | 45 | 2008-12-13: v1.0.0 release 46 | * Bug fixes 47 | 48 | 2008-11-21: v0.9.4 release 49 | * Bug fixes 50 | * Add libusb_attach_kernel_driver() 51 | 52 | 2008-08-23: v0.9.3 release 53 | * Bug fixes 54 | 55 | 2008-07-19: v0.9.2 release 56 | * Bug fixes 57 | 58 | 2008-06-28: v0.9.1 release 59 | * Bug fixes 60 | * Introduce contexts to the API 61 | * Compatibility with new Linux kernel features 62 | 63 | 2008-05-25: v0.9.0 release 64 | * First libusb-1.0 beta release 65 | 66 | -------------------------------------------------------------------------------- /01-cgminer.rules: -------------------------------------------------------------------------------- 1 | # Butterfly Labs FPGA and ASIC devices 2 | ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6014", SUBSYSTEM=="usb", ACTION=="add", MODE="0666", GROUP="plugdev" 3 | 4 | # ModMinerQuad 5 | ATTRS{idVendor}=="1fc9", ATTRS{idProduct}=="0003", SUBSYSTEM=="usb", ACTION=="add", MODE="0666", GROUP="plugdev" 6 | 7 | # Lancelot and Avalon 8 | ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", SUBSYSTEM=="usb", ACTION=="add", MODE="0666", GROUP="plugdev" 9 | 10 | # Icarus 11 | ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", SUBSYSTEM=="usb", ACTION=="add", MODE="0666", GROUP="plugdev" 12 | 13 | # AsicminerUSB and Antminer U1 14 | ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", SUBSYSTEM=="usb", ACTION=="add", MODE="0666", GROUP="plugdev" 15 | 16 | # Cairnsmore1 17 | ATTRS{idVendor}=="067b", ATTRS{idProduct}=="0230", SUBSYSTEM=="usb", ACTION=="add", MODE="0666", GROUP="plugdev" 18 | 19 | # Cairnsmore1-2 20 | ATTRS{idVendor}=="0403", ATTRS{idProduct}=="8350", SUBSYSTEM=="usb", ACTION=="add", MODE="0666", GROUP="plugdev" 21 | 22 | # Ztex 23 | ATTRS{idVendor}=="221a", ATTRS{idProduct}=="0100", SUBSYSTEM=="usb", ACTION=="add", MODE="0666", GROUP="plugdev" 24 | 25 | # BF1 26 | ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="204b", SUBSYSTEM=="usb", ACTION=="add", MODE="0666", GROUP="plugdev" 27 | 28 | # Klondike 29 | ATTRS{idVendor}=="04d8", ATTRS{idProduct}=="f60a", SUBSYSTEM=="usb", ACTION=="add", MODE="0666", GROUP="plugdev" 30 | 31 | # HashFast 32 | ATTRS{idVendor}=="297c", ATTRS{idProduct}=="0001", SUBSYSTEM=="usb", ACTION=="add", MODE="0666", GROUP="plugdev", ENV{ID_MM_DEVICE_IGNORE}="1" 33 | 34 | # BXF 35 | ATTRS{idVendor}=="198c", ATTRS{idProduct}=="b1f1", SUBSYSTEM=="usb", ACTION=="add", MODE="0666", GROUP="plugdev" 36 | 37 | # NF1 38 | ATTRS{idVendor}=="04d8", ATTRS{idProduct}=="00de", SUBSYSTEM=="usb", ACTION=="add", MODE="0666", GROUP="plugdev" 39 | -------------------------------------------------------------------------------- /lib/dummy.c: -------------------------------------------------------------------------------- 1 | /* A dummy file, to prevent empty libraries from breaking builds. 2 | Copyright (C) 2004, 2007, 2009-2011 Free Software Foundation, Inc. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation; either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . */ 16 | 17 | /* Some systems, reportedly OpenBSD and Mac OS X, refuse to create 18 | libraries without any object files. You might get an error like: 19 | 20 | > ar cru .libs/libgl.a 21 | > ar: no archive members specified 22 | 23 | Compiling this file, and adding its object file to the library, will 24 | prevent the library from being empty. */ 25 | 26 | /* Some systems, such as Solaris with cc 5.0, refuse to work with libraries 27 | that don't export any symbol. You might get an error like: 28 | 29 | > cc ... libgnu.a 30 | > ild: (bad file) garbled symbol table in archive ../gllib/libgnu.a 31 | 32 | Compiling this file, and adding its object file to the library, will 33 | prevent the library from exporting no symbols. */ 34 | 35 | #ifdef __sun 36 | /* This declaration ensures that the library will export at least 1 symbol. */ 37 | int gl_dummy_symbol; 38 | #else 39 | /* This declaration is solely to ensure that after preprocessing 40 | this file is never empty. */ 41 | typedef int dummy; 42 | #endif 43 | -------------------------------------------------------------------------------- /lib/sig-handler.h: -------------------------------------------------------------------------------- 1 | /* Convenience declarations when working with . 2 | 3 | Copyright (C) 2008-2011 Free Software Foundation, Inc. 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . */ 17 | 18 | #ifndef _GL_SIG_HANDLER_H 19 | #define _GL_SIG_HANDLER_H 20 | 21 | #include 22 | 23 | /* Convenience type when working with signal handlers. */ 24 | typedef void (*sa_handler_t) (int); 25 | 26 | /* Return the handler of a signal, as a sa_handler_t value regardless 27 | of its true type. The resulting function can be compared to 28 | special values like SIG_IGN but it is not portable to call it. */ 29 | static inline sa_handler_t 30 | get_handler (struct sigaction const *a) 31 | { 32 | #ifdef SA_SIGINFO 33 | /* POSIX says that special values like SIG_IGN can only occur when 34 | action.sa_flags does not contain SA_SIGINFO. But in Linux 2.4, 35 | for example, sa_sigaction and sa_handler are aliases and a signal 36 | is ignored if sa_sigaction (after casting) equals SIG_IGN. So 37 | use (and cast) sa_sigaction in that case. */ 38 | if (a->sa_flags & SA_SIGINFO) 39 | return (sa_handler_t) a->sa_sigaction; 40 | #endif 41 | return a->sa_handler; 42 | } 43 | 44 | #endif /* _GL_SIG_HANDLER_H */ 45 | -------------------------------------------------------------------------------- /ccan/opt/_info: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "config.h" 4 | 5 | /** 6 | * opt - simple command line parsing 7 | * 8 | * Simple but powerful command line parsing. 9 | * 10 | * Example: 11 | * #include 12 | * #include 13 | * #include 14 | * 15 | * static bool someflag; 16 | * static int verbose; 17 | * static char *somestring; 18 | * 19 | * static struct opt_table opts[] = { 20 | * OPT_WITHOUT_ARG("--verbose|-v", opt_inc_intval, &verbose, 21 | * "Verbose mode (can be specified more than once)"), 22 | * OPT_WITHOUT_ARG("--someflag", opt_set_bool, &someflag, 23 | * "Set someflag"), 24 | * OPT_WITH_ARG("--somefile=", opt_set_charp, opt_show_charp, 25 | * &somestring, "Set somefile to "), 26 | * OPT_WITHOUT_ARG("--usage|--help|-h", opt_usage_and_exit, 27 | * "args...\nA silly test program.", 28 | * "Print this message."), 29 | * OPT_ENDTABLE 30 | * }; 31 | * 32 | * int main(int argc, char *argv[]) 33 | * { 34 | * int i; 35 | * 36 | * opt_register_table(opts, NULL); 37 | * // For fun, register an extra one. 38 | * opt_register_noarg("--no-someflag", opt_set_invbool, &someflag, 39 | * "Unset someflag"); 40 | * if (!opt_parse(&argc, argv, opt_log_stderr)) 41 | * exit(1); 42 | * 43 | * printf("someflag = %i, verbose = %i, somestring = %s\n", 44 | * someflag, verbose, somestring); 45 | * printf("%u args left over:", argc - 1); 46 | * for (i = 1; i < argc; i++) 47 | * printf(" %s", argv[i]); 48 | * printf("\n"); 49 | * return 0; 50 | * } 51 | * 52 | * License: GPL (2 or any later version) 53 | * Author: Rusty Russell 54 | */ 55 | int main(int argc, char *argv[]) 56 | { 57 | if (argc != 2) 58 | return 1; 59 | 60 | if (strcmp(argv[1], "depends") == 0) { 61 | printf("ccan/typesafe_cb\n"); 62 | printf("ccan/compiler\n"); 63 | return 0; 64 | } 65 | 66 | return 1; 67 | } 68 | -------------------------------------------------------------------------------- /compat/libusb-1.0/libusb/libusb-1.0.rc: -------------------------------------------------------------------------------- 1 | /* 2 | * For Windows: input this file to the Resoure Compiler to produce a binary 3 | * .res file. This is then embedded in the resultant library (like any other 4 | * compilation object). 5 | * The information can then be queried using standard APIs and can also be 6 | * viewed with utilities such as Windows Explorer. 7 | */ 8 | #include "winresrc.h" 9 | 10 | #include "version.h" 11 | #ifndef LIBUSB_VERSIONSTRING 12 | #define LU_STR(s) #s 13 | #define LU_XSTR(s) LU_STR(s) 14 | #if LIBUSB_NANO > 0 15 | #define LIBUSB_VERSIONSTRING LU_XSTR(LIBUSB_MAJOR) "." LU_XSTR(LIBUSB_MINOR) "." LU_XSTR(LIBUSB_MICRO) "." LU_XSTR(LIBUSB_NANO) LIBUSB_RC "\0" 16 | #else 17 | #define LIBUSB_VERSIONSTRING LU_XSTR(LIBUSB_MAJOR) "." LU_XSTR(LIBUSB_MINOR) "." LU_XSTR(LIBUSB_MICRO) LIBUSB_RC "\0" 18 | #endif 19 | #endif 20 | 21 | VS_VERSION_INFO VERSIONINFO 22 | FILEVERSION LIBUSB_MAJOR,LIBUSB_MINOR,LIBUSB_MICRO,LIBUSB_NANO 23 | PRODUCTVERSION LIBUSB_MAJOR,LIBUSB_MINOR,LIBUSB_MICRO,LIBUSB_NANO 24 | FILEFLAGSMASK 0x3fL 25 | #ifdef _DEBUG 26 | FILEFLAGS 0x1L 27 | #else 28 | FILEFLAGS 0x0L 29 | #endif 30 | FILEOS 0x40004L 31 | FILETYPE 0x2L 32 | FILESUBTYPE 0x0L 33 | BEGIN 34 | BLOCK "StringFileInfo" 35 | BEGIN 36 | BLOCK "040904b0" 37 | BEGIN 38 | VALUE "Comments", "\0" 39 | VALUE "CompanyName", "libusb.org\0" 40 | VALUE "FileDescription", "C library for writing portable USB drivers in userspace\0" 41 | VALUE "FileVersion", LIBUSB_VERSIONSTRING 42 | VALUE "InternalName", "libusb\0" 43 | VALUE "LegalCopyright", "See individual source files, GNU LGPL v2.1 or later.\0" 44 | VALUE "LegalTrademarks", "http://www.gnu.org/licenses/lgpl-2.1.html\0" 45 | VALUE "OriginalFilename", "libusb-1.0.dll\0" 46 | VALUE "PrivateBuild", "\0" 47 | VALUE "ProductName", "libusb-1.0\0" 48 | VALUE "ProductVersion", LIBUSB_VERSIONSTRING 49 | VALUE "SpecialBuild", "\0" 50 | END 51 | END 52 | BLOCK "VarFileInfo" 53 | BEGIN 54 | VALUE "Translation", 0x409, 1200 55 | END 56 | END 57 | -------------------------------------------------------------------------------- /compat/libusb-1.0/libusb/os/threads_posix.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libusb synchronization using POSIX Threads 3 | * 4 | * Copyright (C) 2010 Peter Stuge 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef LIBUSB_THREADS_POSIX_H 22 | #define LIBUSB_THREADS_POSIX_H 23 | 24 | #include 25 | 26 | #define usbi_mutex_static_t pthread_mutex_t 27 | #define USBI_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER 28 | #define usbi_mutex_static_lock pthread_mutex_lock 29 | #define usbi_mutex_static_unlock pthread_mutex_unlock 30 | 31 | #define usbi_mutex_t pthread_mutex_t 32 | #define usbi_mutex_init pthread_mutex_init 33 | #define usbi_mutex_lock pthread_mutex_lock 34 | #define usbi_mutex_unlock pthread_mutex_unlock 35 | #define usbi_mutex_trylock pthread_mutex_trylock 36 | #define usbi_mutex_destroy pthread_mutex_destroy 37 | 38 | #define usbi_cond_t pthread_cond_t 39 | #define usbi_cond_init pthread_cond_init 40 | #define usbi_cond_wait pthread_cond_wait 41 | #define usbi_cond_timedwait pthread_cond_timedwait 42 | #define usbi_cond_broadcast pthread_cond_broadcast 43 | #define usbi_cond_destroy pthread_cond_destroy 44 | #define usbi_cond_signal pthread_cond_signal 45 | 46 | extern int usbi_mutex_init_recursive(pthread_mutex_t *mutex, pthread_mutexattr_t *attr); 47 | 48 | #endif /* LIBUSB_THREADS_POSIX_H */ 49 | -------------------------------------------------------------------------------- /compat.h: -------------------------------------------------------------------------------- 1 | #ifndef __COMPAT_H__ 2 | #define __COMPAT_H__ 3 | 4 | #ifdef WIN32 5 | #include "config.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "miner.h" // for timersub 12 | #include "util.h" 13 | 14 | #include 15 | 16 | #ifndef HAVE_LIBWINPTHREAD 17 | static inline int nanosleep(const struct timespec *req, struct timespec *rem) 18 | { 19 | struct timeval tstart; 20 | DWORD msecs; 21 | 22 | cgtime(&tstart); 23 | msecs = (req->tv_sec * 1000) + ((999999 + req->tv_nsec) / 1000000); 24 | 25 | if (SleepEx(msecs, true) == WAIT_IO_COMPLETION) { 26 | if (rem) { 27 | struct timeval tdone, tnow, tleft; 28 | tdone.tv_sec = tstart.tv_sec + req->tv_sec; 29 | tdone.tv_usec = tstart.tv_usec + ((999 + req->tv_nsec) / 1000); 30 | if (tdone.tv_usec > 1000000) { 31 | tdone.tv_usec -= 1000000; 32 | ++tdone.tv_sec; 33 | } 34 | 35 | cgtime(&tnow); 36 | if (timercmp(&tnow, &tdone, >)) 37 | return 0; 38 | timersub(&tdone, &tnow, &tleft); 39 | 40 | rem->tv_sec = tleft.tv_sec; 41 | rem->tv_nsec = tleft.tv_usec * 1000; 42 | } 43 | errno = EINTR; 44 | return -1; 45 | } 46 | return 0; 47 | } 48 | #endif 49 | 50 | static inline int sleep(unsigned int secs) 51 | { 52 | struct timespec req, rem; 53 | req.tv_sec = secs; 54 | req.tv_nsec = 0; 55 | if (!nanosleep(&req, &rem)) 56 | return 0; 57 | return rem.tv_sec + (rem.tv_nsec ? 1 : 0); 58 | } 59 | 60 | enum { 61 | PRIO_PROCESS = 0, 62 | }; 63 | 64 | static inline int setpriority(__maybe_unused int which, __maybe_unused int who, __maybe_unused int prio) 65 | { 66 | /* FIXME - actually do something */ 67 | return 0; 68 | } 69 | 70 | typedef unsigned long int ulong; 71 | typedef unsigned short int ushort; 72 | typedef unsigned int uint; 73 | 74 | #ifndef __SUSECONDS_T_TYPE 75 | typedef long suseconds_t; 76 | #endif 77 | 78 | #ifdef HAVE_LIBWINPTHREAD 79 | #define PTH(thr) ((thr)->pth) 80 | #else 81 | #define PTH(thr) ((thr)->pth.p) 82 | #endif 83 | 84 | #else 85 | #define PTH(thr) ((thr)->pth) 86 | #endif /* WIN32 */ 87 | 88 | #endif /* __COMPAT_H__ */ 89 | -------------------------------------------------------------------------------- /m4/mmap-anon.m4: -------------------------------------------------------------------------------- 1 | # mmap-anon.m4 serial 9 2 | dnl Copyright (C) 2005, 2007, 2009-2011 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | # Detect how mmap can be used to create anonymous (not file-backed) memory 8 | # mappings. 9 | # - On Linux, AIX, OSF/1, Solaris, Cygwin, Interix, Haiku, both MAP_ANONYMOUS 10 | # and MAP_ANON exist and have the same value. 11 | # - On HP-UX, only MAP_ANONYMOUS exists. 12 | # - On MacOS X, FreeBSD, NetBSD, OpenBSD, only MAP_ANON exists. 13 | # - On IRIX, neither exists, and a file descriptor opened to /dev/zero must be 14 | # used. 15 | 16 | AC_DEFUN([gl_FUNC_MMAP_ANON], 17 | [ 18 | dnl Persuade glibc to define MAP_ANONYMOUS. 19 | AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) 20 | 21 | # Check for mmap(). Don't use AC_FUNC_MMAP, because it checks too much: it 22 | # fails on HP-UX 11, because MAP_FIXED mappings do not work. But this is 23 | # irrelevant for anonymous mappings. 24 | AC_CHECK_FUNC([mmap], [gl_have_mmap=yes], [gl_have_mmap=no]) 25 | 26 | # Try to allow MAP_ANONYMOUS. 27 | gl_have_mmap_anonymous=no 28 | if test $gl_have_mmap = yes; then 29 | AC_MSG_CHECKING([for MAP_ANONYMOUS]) 30 | AC_EGREP_CPP([I cant identify this map.], [ 31 | #include 32 | #ifdef MAP_ANONYMOUS 33 | I cant identify this map. 34 | #endif 35 | ], 36 | [gl_have_mmap_anonymous=yes]) 37 | if test $gl_have_mmap_anonymous != yes; then 38 | AC_EGREP_CPP([I cant identify this map.], [ 39 | #include 40 | #ifdef MAP_ANON 41 | I cant identify this map. 42 | #endif 43 | ], 44 | [AC_DEFINE([MAP_ANONYMOUS], [MAP_ANON], 45 | [Define to a substitute value for mmap()'s MAP_ANONYMOUS flag.]) 46 | gl_have_mmap_anonymous=yes]) 47 | fi 48 | AC_MSG_RESULT([$gl_have_mmap_anonymous]) 49 | if test $gl_have_mmap_anonymous = yes; then 50 | AC_DEFINE([HAVE_MAP_ANONYMOUS], [1], 51 | [Define to 1 if mmap()'s MAP_ANONYMOUS flag is available after including 52 | config.h and .]) 53 | fi 54 | fi 55 | ]) 56 | -------------------------------------------------------------------------------- /m4/multiarch.m4: -------------------------------------------------------------------------------- 1 | # multiarch.m4 serial 6 2 | dnl Copyright (C) 2008-2011 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | # Determine whether the compiler is or may be producing universal binaries. 8 | # 9 | # On MacOS X 10.5 and later systems, the user can create libraries and 10 | # executables that work on multiple system types--known as "fat" or 11 | # "universal" binaries--by specifying multiple '-arch' options to the 12 | # compiler but only a single '-arch' option to the preprocessor. Like 13 | # this: 14 | # 15 | # ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ 16 | # CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ 17 | # CPP="gcc -E" CXXCPP="g++ -E" 18 | # 19 | # Detect this situation and set APPLE_UNIVERSAL_BUILD accordingly. 20 | 21 | AC_DEFUN_ONCE([gl_MULTIARCH], 22 | [ 23 | dnl Code similar to autoconf-2.63 AC_C_BIGENDIAN. 24 | gl_cv_c_multiarch=no 25 | AC_COMPILE_IFELSE( 26 | [AC_LANG_SOURCE( 27 | [[#ifndef __APPLE_CC__ 28 | not a universal capable compiler 29 | #endif 30 | typedef int dummy; 31 | ]])], 32 | [ 33 | dnl Check for potential -arch flags. It is not universal unless 34 | dnl there are at least two -arch flags with different values. 35 | arch= 36 | prev= 37 | for word in ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}; do 38 | if test -n "$prev"; then 39 | case $word in 40 | i?86 | x86_64 | ppc | ppc64) 41 | if test -z "$arch" || test "$arch" = "$word"; then 42 | arch="$word" 43 | else 44 | gl_cv_c_multiarch=yes 45 | fi 46 | ;; 47 | esac 48 | prev= 49 | else 50 | if test "x$word" = "x-arch"; then 51 | prev=arch 52 | fi 53 | fi 54 | done 55 | ]) 56 | if test $gl_cv_c_multiarch = yes; then 57 | APPLE_UNIVERSAL_BUILD=1 58 | else 59 | APPLE_UNIVERSAL_BUILD=0 60 | fi 61 | AC_SUBST([APPLE_UNIVERSAL_BUILD]) 62 | ]) 63 | -------------------------------------------------------------------------------- /m4/warn-on-use.m4: -------------------------------------------------------------------------------- 1 | # warn-on-use.m4 serial 2 2 | dnl Copyright (C) 2010-2011 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | # gl_WARN_ON_USE_PREPARE(INCLUDES, NAMES) 8 | # --------------------------------------- 9 | # For each whitespace-separated element in the list of NAMES, define 10 | # HAVE_RAW_DECL_name if the function has a declaration among INCLUDES 11 | # even after being undefined as a macro. 12 | # 13 | # See warn-on-use.h for some hints on how to poison function names, as 14 | # well as ideas on poisoning global variables and macros. NAMES may 15 | # include global variables, but remember that only functions work with 16 | # _GL_WARN_ON_USE. Typically, INCLUDES only needs to list a single 17 | # header, but if the replacement header pulls in other headers because 18 | # some systems declare functions in the wrong header, then INCLUDES 19 | # should do likewise. 20 | # 21 | # If you assume C89, then it is generally safe to assume declarations 22 | # for functions declared in that standard (such as gets) without 23 | # needing gl_WARN_ON_USE_PREPARE. 24 | AC_DEFUN([gl_WARN_ON_USE_PREPARE], 25 | [ 26 | m4_foreach_w([gl_decl], [$2], 27 | [AH_TEMPLATE([HAVE_RAW_DECL_]AS_TR_CPP(m4_defn([gl_decl])), 28 | [Define to 1 if ]m4_defn([gl_decl])[ is declared even after 29 | undefining macros.])])dnl 30 | for gl_func in m4_flatten([$2]); do 31 | AS_VAR_PUSHDEF([gl_Symbol], [gl_cv_have_raw_decl_$gl_func])dnl 32 | AC_CACHE_CHECK([whether $gl_func is declared without a macro], 33 | gl_Symbol, 34 | [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$1], 35 | [@%:@undef $gl_func 36 | (void) $gl_func;])], 37 | [AS_VAR_SET(gl_Symbol, [yes])], [AS_VAR_SET(gl_Symbol, [no])])]) 38 | AS_VAR_IF(gl_Symbol, [yes], 39 | [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_RAW_DECL_$gl_func]), [1]) 40 | dnl shortcut - if the raw declaration exists, then set a cache 41 | dnl variable to allow skipping any later AC_CHECK_DECL efforts 42 | eval ac_cv_have_decl_$gl_func=yes]) 43 | AS_VAR_POPDEF([gl_Symbol])dnl 44 | done 45 | ]) 46 | -------------------------------------------------------------------------------- /ccan/opt/test/run-iter.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "utils.h" 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | static void reset_options(void) 13 | { 14 | free(opt_table); 15 | opt_table = NULL; 16 | opt_count = opt_num_short = opt_num_short_arg = opt_num_long = 0; 17 | } 18 | 19 | /* Test iterators. */ 20 | int main(int argc, char *argv[]) 21 | { 22 | unsigned j, i, len = 0; 23 | const char *p; 24 | 25 | plan_tests(37 * 2); 26 | for (j = 0; j < 2; j ++) { 27 | reset_options(); 28 | /* Giving subtable a title makes an extra entry! */ 29 | opt_register_table(subtables, j == 0 ? NULL : "subtable"); 30 | 31 | p = first_lopt(&i, &len); 32 | ok1(i == j + 0); 33 | ok1(len == 3); 34 | ok1(strncmp(p, "jjj", len) == 0); 35 | p = next_lopt(p, &i, &len); 36 | ok1(i == j + 0); 37 | ok1(len == 3); 38 | ok1(strncmp(p, "lll", len) == 0); 39 | p = next_lopt(p, &i, &len); 40 | ok1(i == j + 1); 41 | ok1(len == 3); 42 | ok1(strncmp(p, "mmm", len) == 0); 43 | p = next_lopt(p, &i, &len); 44 | ok1(i == j + 5); 45 | ok1(len == 3); 46 | ok1(strncmp(p, "ddd", len) == 0); 47 | p = next_lopt(p, &i, &len); 48 | ok1(i == j + 6); 49 | ok1(len == 3); 50 | ok1(strncmp(p, "eee", len) == 0); 51 | p = next_lopt(p, &i, &len); 52 | ok1(i == j + 7); 53 | ok1(len == 3); 54 | ok1(strncmp(p, "ggg", len) == 0); 55 | p = next_lopt(p, &i, &len); 56 | ok1(i == j + 8); 57 | ok1(len == 3); 58 | ok1(strncmp(p, "hhh", len) == 0); 59 | p = next_lopt(p, &i, &len); 60 | ok1(!p); 61 | 62 | p = first_sopt(&i); 63 | ok1(i == j + 0); 64 | ok1(*p == 'j'); 65 | p = next_sopt(p, &i); 66 | ok1(i == j + 0); 67 | ok1(*p == 'l'); 68 | p = next_sopt(p, &i); 69 | ok1(i == j + 1); 70 | ok1(*p == 'm'); 71 | p = next_sopt(p, &i); 72 | ok1(i == j + 2); 73 | ok1(*p == 'a'); 74 | p = next_sopt(p, &i); 75 | ok1(i == j + 3); 76 | ok1(*p == 'b'); 77 | p = next_sopt(p, &i); 78 | ok1(i == j + 7); 79 | ok1(*p == 'g'); 80 | p = next_sopt(p, &i); 81 | ok1(i == j + 8); 82 | ok1(*p == 'h'); 83 | p = next_sopt(p, &i); 84 | ok1(!p); 85 | } 86 | 87 | return exit_status(); 88 | } 89 | -------------------------------------------------------------------------------- /hexdump.c: -------------------------------------------------------------------------------- 1 | /* 2 | * hexdump implementation without depenecies to *printf() 3 | * output is equal to 'hexdump -C' 4 | * should be compatible to 64bit architectures 5 | * 6 | * Copyright (c) 2009 Daniel Mack 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #define hex_print(p) applog(LOG_DEBUG, "%s", p) 23 | 24 | static char nibble[] = { 25 | '0', '1', '2', '3', '4', '5', '6', '7', 26 | '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; 27 | 28 | #define BYTES_PER_LINE 0x10 29 | 30 | void hexdump(const uint8_t *p, unsigned int len) 31 | { 32 | unsigned int i, addr; 33 | unsigned int wordlen = sizeof(void*); 34 | unsigned char v, line[BYTES_PER_LINE * 5]; 35 | 36 | for (addr = 0; addr < len; addr += BYTES_PER_LINE) { 37 | /* clear line */ 38 | for (i = 0; i < sizeof(line); i++) { 39 | if (i == wordlen * 2 + 52 || 40 | i == wordlen * 2 + 69) { 41 | line[i] = '|'; 42 | continue; 43 | } 44 | 45 | if (i == wordlen * 2 + 70) { 46 | line[i] = '\0'; 47 | continue; 48 | } 49 | 50 | line[i] = ' '; 51 | } 52 | 53 | /* print address */ 54 | for (i = 0; i < wordlen * 2; i++) { 55 | v = addr >> ((wordlen * 2 - i - 1) * 4); 56 | line[i] = nibble[v & 0xf]; 57 | } 58 | 59 | /* dump content */ 60 | for (i = 0; i < BYTES_PER_LINE; i++) { 61 | int pos = (wordlen * 2) + 3 + (i / 8); 62 | 63 | if (addr + i >= len) 64 | break; 65 | 66 | v = p[addr + i]; 67 | line[pos + (i * 3) + 0] = nibble[v >> 4]; 68 | line[pos + (i * 3) + 1] = nibble[v & 0xf]; 69 | 70 | /* character printable? */ 71 | line[(wordlen * 2) + 53 + i] = 72 | (v >= ' ' && v <= '~') ? v : '.'; 73 | } 74 | 75 | hex_print(line); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /logging.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Con Kolivas 3 | * Copyright 2013 Andrew Smith 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation; either version 3 of the License, or (at your option) 8 | * any later version. See COPYING for more details. 9 | */ 10 | 11 | #include "config.h" 12 | 13 | #include 14 | 15 | #include "logging.h" 16 | #include "miner.h" 17 | 18 | bool opt_debug = false; 19 | bool opt_log_output = false; 20 | 21 | /* per default priorities higher than LOG_NOTICE are logged */ 22 | int opt_log_level = LOG_NOTICE; 23 | 24 | static void my_log_curses(int prio, const char *datetime, const char *str, bool force) 25 | { 26 | if (opt_quiet && prio != LOG_ERR) 27 | return; 28 | 29 | /* Mutex could be locked by dead thread on shutdown so forcelog will 30 | * invalidate any console lock status. */ 31 | if (force) { 32 | mutex_trylock(&console_lock); 33 | mutex_unlock(&console_lock); 34 | } 35 | #ifdef HAVE_CURSES 36 | extern bool use_curses; 37 | if (use_curses && log_curses_only(prio, datetime, str)) 38 | ; 39 | else 40 | #endif 41 | { 42 | mutex_lock(&console_lock); 43 | printf("%s%s%s", datetime, str, " \n"); 44 | mutex_unlock(&console_lock); 45 | } 46 | } 47 | 48 | /* high-level logging function, based on global opt_log_level */ 49 | 50 | /* 51 | * log function 52 | */ 53 | void _applog(int prio, const char *str, bool force) 54 | { 55 | #ifdef HAVE_SYSLOG_H 56 | if (use_syslog) { 57 | syslog(prio, "%s", str); 58 | } 59 | #else 60 | if (0) {} 61 | #endif 62 | else { 63 | char datetime[64]; 64 | struct timeval tv = {0, 0}; 65 | struct tm *tm; 66 | 67 | cgtime(&tv); 68 | 69 | const time_t tmp_time = tv.tv_sec; 70 | tm = localtime(&tmp_time); 71 | 72 | snprintf(datetime, sizeof(datetime), " [%d-%02d-%02d %02d:%02d:%02d] ", 73 | tm->tm_year + 1900, 74 | tm->tm_mon + 1, 75 | tm->tm_mday, 76 | tm->tm_hour, 77 | tm->tm_min, 78 | tm->tm_sec); 79 | 80 | /* Only output to stderr if it's not going to the screen as well */ 81 | if (!isatty(fileno((FILE *)stderr))) { 82 | fprintf(stderr, "%s%s\n", datetime, str); /* atomic write to stderr */ 83 | fflush(stderr); 84 | } 85 | 86 | my_log_curses(prio, datetime, str, force); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /m4/signal_h.m4: -------------------------------------------------------------------------------- 1 | # signal_h.m4 serial 12 2 | dnl Copyright (C) 2007-2011 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | AC_DEFUN([gl_SIGNAL_H], 8 | [ 9 | AC_REQUIRE([gl_SIGNAL_H_DEFAULTS]) 10 | gl_NEXT_HEADERS([signal.h]) 11 | 12 | # AIX declares sig_atomic_t to already include volatile, and C89 compilers 13 | # then choke on 'volatile sig_atomic_t'. C99 requires that it compile. 14 | AC_CHECK_TYPE([volatile sig_atomic_t], [], 15 | [HAVE_TYPE_VOLATILE_SIG_ATOMIC_T=0], [[ 16 | #include 17 | ]]) 18 | 19 | AC_REQUIRE([AC_TYPE_UID_T]) 20 | 21 | dnl Persuade glibc to define sighandler_t. 22 | AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) 23 | AC_CHECK_TYPE([sighandler_t], [], [HAVE_SIGHANDLER_T=0], [[ 24 | #include 25 | ]]) 26 | 27 | dnl Check for declarations of anything we want to poison if the 28 | dnl corresponding gnulib module is not in use. 29 | gl_WARN_ON_USE_PREPARE([[#include 30 | ]], [sigaction sigaddset sigdelset sigemptyset sigfillset sigismember 31 | sigpending sigprocmask]) 32 | ]) 33 | 34 | AC_DEFUN([gl_SIGNAL_MODULE_INDICATOR], 35 | [ 36 | dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 37 | AC_REQUIRE([gl_SIGNAL_H_DEFAULTS]) 38 | gl_MODULE_INDICATOR_SET_VARIABLE([$1]) 39 | dnl Define it also as a C macro, for the benefit of the unit tests. 40 | gl_MODULE_INDICATOR_FOR_TESTS([$1]) 41 | ]) 42 | 43 | AC_DEFUN([gl_SIGNAL_H_DEFAULTS], 44 | [ 45 | GNULIB_SIGNAL_H_SIGPIPE=0; AC_SUBST([GNULIB_SIGNAL_H_SIGPIPE]) 46 | GNULIB_SIGPROCMASK=0; AC_SUBST([GNULIB_SIGPROCMASK]) 47 | GNULIB_SIGACTION=0; AC_SUBST([GNULIB_SIGACTION]) 48 | dnl Assume proper GNU behavior unless another module says otherwise. 49 | HAVE_POSIX_SIGNALBLOCKING=1; AC_SUBST([HAVE_POSIX_SIGNALBLOCKING]) 50 | HAVE_SIGSET_T=1; AC_SUBST([HAVE_SIGSET_T]) 51 | HAVE_SIGINFO_T=1; AC_SUBST([HAVE_SIGINFO_T]) 52 | HAVE_SIGACTION=1; AC_SUBST([HAVE_SIGACTION]) 53 | HAVE_STRUCT_SIGACTION_SA_SIGACTION=1; 54 | AC_SUBST([HAVE_STRUCT_SIGACTION_SA_SIGACTION]) 55 | HAVE_TYPE_VOLATILE_SIG_ATOMIC_T=1; 56 | AC_SUBST([HAVE_TYPE_VOLATILE_SIG_ATOMIC_T]) 57 | HAVE_SIGHANDLER_T=1; AC_SUBST([HAVE_SIGHANDLER_T]) 58 | ]) 59 | -------------------------------------------------------------------------------- /driver-bitfury.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Con Kolivas 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the Free 6 | * Software Foundation; either version 3 of the License, or (at your option) 7 | * any later version. See COPYING for more details. 8 | */ 9 | 10 | #ifndef BITFURY_H 11 | #define BITFURY_H 12 | 13 | #include "miner.h" 14 | #include "usbutils.h" 15 | #include "mcp2210.h" 16 | 17 | #define BXF_CLOCK_DEFAULT 54 18 | #define BXF_CLOCK_OFF 0 19 | #define BXF_CLOCK_MIN 32 20 | #define BXF_CLOCK_MAX 63 // Not really used since we only get hw errors above default 21 | 22 | /* In tenths of a degree */ 23 | #define BXF_TEMP_TARGET 820 24 | #define BXF_TEMP_HYSTERESIS 30 25 | 26 | extern int opt_bxf_temp_target; 27 | extern int opt_nf1_bits; 28 | 29 | #define NF1_PIN_LED 0 30 | #define NF1_PIN_SCK_OVR 5 31 | #define NF1_PIN_PWR_EN 6 32 | 33 | #define SPIBUF_SIZE 16384 34 | #define BITFURY_REFRESH_DELAY 100 35 | 36 | struct bitfury_payload { 37 | unsigned char midstate[32]; 38 | unsigned int junk[8]; 39 | unsigned m7; 40 | unsigned ntime; 41 | unsigned nbits; 42 | unsigned nnonce; 43 | }; 44 | 45 | struct bitfury_info { 46 | struct cgpu_info *base_cgpu; 47 | struct thr_info *thr; 48 | enum sub_ident ident; 49 | int nonces; 50 | int total_nonces; 51 | double saved_nonces; 52 | int cycles; 53 | bool valid; /* Set on first valid data being found */ 54 | 55 | /* BF1 specific data */ 56 | uint8_t version; 57 | char product[8]; 58 | uint32_t serial; 59 | struct timeval tv_start; 60 | 61 | /* BXF specific data */ 62 | pthread_mutex_t lock; 63 | pthread_t read_thr; 64 | double temperature; 65 | int last_decitemp; 66 | int max_decitemp; 67 | int temp_target; 68 | int work_id; // Current work->subid 69 | int no_matching_work; 70 | int maxroll; // Last maxroll sent to device 71 | int ver_major; 72 | int ver_minor; 73 | int hw_rev; 74 | int chips; 75 | uint8_t clocks; // There are two but we set them equal 76 | int filtered_hw[2]; // Hardware errors we're told about but are filtered 77 | int job[2]; // Completed jobs we're told about 78 | int submits[2]; // Submitted responses 79 | 80 | /* NF1 specific data */ 81 | struct mcp_settings mcp; 82 | char spibuf[SPIBUF_SIZE]; 83 | unsigned int spibufsz; 84 | int osc6_bits; 85 | struct bitfury_payload payload; 86 | struct bitfury_payload opayload; 87 | unsigned newbuf[17]; 88 | unsigned oldbuf[17]; 89 | bool job_switched; 90 | bool second_run; 91 | struct work *work; 92 | struct work *owork; 93 | }; 94 | 95 | #endif /* BITFURY_H */ 96 | -------------------------------------------------------------------------------- /api-example.php: -------------------------------------------------------------------------------- 1 | 0) 71 | { 72 | $items = explode(',', $obj); 73 | $item = $items[0]; 74 | $id = explode('=', $items[0], 2); 75 | if (count($id) == 1 or !ctype_digit($id[1])) 76 | $name = $id[0]; 77 | else 78 | $name = $id[0].$id[1]; 79 | 80 | if (strlen($name) == 0) 81 | $name = 'null'; 82 | 83 | if (isset($data[$name])) 84 | { 85 | $num = 1; 86 | while (isset($data[$name.$num])) 87 | $num++; 88 | $name .= $num; 89 | } 90 | 91 | $counter = 0; 92 | foreach ($items as $item) 93 | { 94 | $id = explode('=', $item, 2); 95 | if (count($id) == 2) 96 | $data[$name][$id[0]] = $id[1]; 97 | else 98 | $data[$name][$counter] = $id[0]; 99 | 100 | $counter++; 101 | } 102 | } 103 | } 104 | 105 | return $data; 106 | } 107 | 108 | return null; 109 | } 110 | # 111 | if (isset($argv) and count($argv) > 1) 112 | $r = request($argv[1]); 113 | else 114 | $r = request('summary'); 115 | # 116 | echo print_r($r, true)."\n"; 117 | # 118 | ?> 119 | -------------------------------------------------------------------------------- /compat/libusb-1.0/libusb/hotplug.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; indent-tabs-mode:nil ; c-basic-offset:8 -*- */ 2 | /* 3 | * Hotplug support for libusb 1.0 4 | * Copyright (C) 2012 Nathan Hjelm 5 | * Copyright (C) 2012 Peter Stuge 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #if !defined(USBI_HOTPLUG_H) 23 | #define USBI_HOTPLUG_H 24 | 25 | /** \ingroup hotplug 26 | * The hotplug callback structure. The user populates this structure with 27 | * libusb_hotplug_prepare_callback() and then calls libusb_hotplug_register_callback() 28 | * to receive notification of hotplug events. 29 | */ 30 | struct libusb_hotplug_callback { 31 | /** Context this callback is associated with */ 32 | struct libusb_context *ctx; 33 | 34 | /** Vendor ID to match or LIBUSB_HOTPLUG_MATCH_ANY */ 35 | int vendor_id; 36 | 37 | /** Product ID to match or LIBUSB_HOTPLUG_MATCH_ANY */ 38 | int product_id; 39 | 40 | /** Device class to match or LIBUSB_HOTPLUG_MATCH_ANY */ 41 | int dev_class; 42 | 43 | /** Hotplug callback flags */ 44 | libusb_hotplug_flag flags; 45 | 46 | /** Event(s) that will trigger this callback */ 47 | libusb_hotplug_event events; 48 | 49 | /** Callback function to invoke for matching event/device */ 50 | libusb_hotplug_callback_fn cb; 51 | 52 | /** Handle for this callback (used to match on deregister) */ 53 | libusb_hotplug_callback_handle handle; 54 | 55 | /** User data that will be passed to the callback function */ 56 | void *user_data; 57 | 58 | /** Callback is marked for deletion */ 59 | int needs_free; 60 | 61 | /** List this callback is registered in (ctx->hotplug_cbs) */ 62 | struct list_head list; 63 | }; 64 | 65 | typedef struct libusb_hotplug_callback libusb_hotplug_callback; 66 | 67 | struct libusb_hotplug_message { 68 | libusb_hotplug_event event; 69 | struct libusb_device *device; 70 | }; 71 | 72 | typedef struct libusb_hotplug_message libusb_hotplug_message; 73 | 74 | void usbi_hotplug_deregister_all(struct libusb_context *ctx); 75 | void usbi_hotplug_match(struct libusb_device *dev, libusb_hotplug_event event); 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /compat/jansson-2.5/src/jansson_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2013 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef JANSSON_PRIVATE_H 9 | #define JANSSON_PRIVATE_H 10 | 11 | #include 12 | #include "jansson.h" 13 | #include "hashtable.h" 14 | #include "strbuffer.h" 15 | 16 | #define container_of(ptr_, type_, member_) \ 17 | ((type_ *)((char *)ptr_ - offsetof(type_, member_))) 18 | 19 | /* On some platforms, max() may already be defined */ 20 | #ifndef max 21 | #define max(a, b) ((a) > (b) ? (a) : (b)) 22 | #endif 23 | 24 | /* va_copy is a C99 feature. In C89 implementations, it's sometimes 25 | available as __va_copy. If not, memcpy() should do the trick. */ 26 | #ifndef va_copy 27 | #ifdef __va_copy 28 | #define va_copy __va_copy 29 | #else 30 | #define va_copy(a, b) memcpy(&(a), &(b), sizeof(va_list)) 31 | #endif 32 | #endif 33 | 34 | typedef struct { 35 | json_t json; 36 | hashtable_t hashtable; 37 | size_t serial; 38 | int visited; 39 | } json_object_t; 40 | 41 | typedef struct { 42 | json_t json; 43 | size_t size; 44 | size_t entries; 45 | json_t **table; 46 | int visited; 47 | } json_array_t; 48 | 49 | typedef struct { 50 | json_t json; 51 | char *value; 52 | } json_string_t; 53 | 54 | typedef struct { 55 | json_t json; 56 | double value; 57 | } json_real_t; 58 | 59 | typedef struct { 60 | json_t json; 61 | json_int_t value; 62 | } json_integer_t; 63 | 64 | #define json_to_object(json_) container_of(json_, json_object_t, json) 65 | #define json_to_array(json_) container_of(json_, json_array_t, json) 66 | #define json_to_string(json_) container_of(json_, json_string_t, json) 67 | #define json_to_real(json_) container_of(json_, json_real_t, json) 68 | #define json_to_integer(json_) container_of(json_, json_integer_t, json) 69 | 70 | void jsonp_error_init(json_error_t *error, const char *source); 71 | void jsonp_error_set_source(json_error_t *error, const char *source); 72 | void jsonp_error_set(json_error_t *error, int line, int column, 73 | size_t position, const char *msg, ...); 74 | void jsonp_error_vset(json_error_t *error, int line, int column, 75 | size_t position, const char *msg, va_list ap); 76 | 77 | /* Locale independent string<->double conversions */ 78 | int jsonp_strtod(strbuffer_t *strbuffer, double *out); 79 | int jsonp_dtostr(char *buffer, size_t size, double value); 80 | 81 | /* Wrappers for custom memory functions */ 82 | void* jsonp_malloc(size_t size); 83 | void jsonp_free(void *ptr); 84 | char *jsonp_strndup(const char *str, size_t length); 85 | char *jsonp_strdup(const char *str); 86 | 87 | /* Windows compatibility */ 88 | #ifdef _WIN32 89 | #define snprintf _snprintf 90 | #define vsnprintf _vsnprintf 91 | #endif 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /ccan/typesafe_cb/test/run.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | static char dummy = 0; 7 | 8 | /* The example usage. */ 9 | static void _set_some_value(void *val) 10 | { 11 | ok1(val == &dummy); 12 | } 13 | 14 | #define set_some_value(expr) \ 15 | _set_some_value(typesafe_cb_cast(void *, unsigned long, (expr))) 16 | 17 | static void _callback_onearg(void (*fn)(void *arg), void *arg) 18 | { 19 | fn(arg); 20 | } 21 | 22 | static void _callback_preargs(void (*fn)(int a, int b, void *arg), void *arg) 23 | { 24 | fn(1, 2, arg); 25 | } 26 | 27 | static void _callback_postargs(void (*fn)(void *arg, int a, int b), void *arg) 28 | { 29 | fn(arg, 1, 2); 30 | } 31 | 32 | #define callback_onearg(cb, arg) \ 33 | _callback_onearg(typesafe_cb(void, void *, (cb), (arg)), (arg)) 34 | 35 | #define callback_preargs(cb, arg) \ 36 | _callback_preargs(typesafe_cb_preargs(void, void *, (cb), (arg), int, int), (arg)) 37 | 38 | #define callback_postargs(cb, arg) \ 39 | _callback_postargs(typesafe_cb_postargs(void, void *, (cb), (arg), int, int), (arg)) 40 | 41 | static void my_callback_onearg(char *p) 42 | { 43 | ok1(strcmp(p, "hello world") == 0); 44 | } 45 | 46 | static void my_callback_preargs(int a, int b, char *p) 47 | { 48 | ok1(a == 1); 49 | ok1(b == 2); 50 | ok1(strcmp(p, "hello world") == 0); 51 | } 52 | 53 | static void my_callback_postargs(char *p, int a, int b) 54 | { 55 | ok1(a == 1); 56 | ok1(b == 2); 57 | ok1(strcmp(p, "hello world") == 0); 58 | } 59 | 60 | /* This is simply a compile test; we promised typesafe_cb_cast can be in a 61 | * static initializer. */ 62 | struct callback_onearg 63 | { 64 | void (*fn)(void *arg); 65 | const void *arg; 66 | }; 67 | 68 | struct callback_onearg cb_onearg 69 | = { typesafe_cb(void, void *, my_callback_onearg, (char *)(intptr_t)"hello world"), 70 | "hello world" }; 71 | 72 | struct callback_preargs 73 | { 74 | void (*fn)(int a, int b, void *arg); 75 | const void *arg; 76 | }; 77 | 78 | struct callback_preargs cb_preargs 79 | = { typesafe_cb_preargs(void, void *, my_callback_preargs, 80 | (char *)(intptr_t)"hi", int, int), "hi" }; 81 | 82 | struct callback_postargs 83 | { 84 | void (*fn)(void *arg, int a, int b); 85 | const void *arg; 86 | }; 87 | 88 | struct callback_postargs cb_postargs 89 | = { typesafe_cb_postargs(void, void *, my_callback_postargs, 90 | (char *)(intptr_t)"hi", int, int), "hi" }; 91 | 92 | int main(int argc, char *argv[]) 93 | { 94 | void *p = &dummy; 95 | unsigned long l = (unsigned long)p; 96 | char str[] = "hello world"; 97 | 98 | plan_tests(2 + 1 + 3 + 3); 99 | set_some_value(p); 100 | set_some_value(l); 101 | 102 | callback_onearg(my_callback_onearg, str); 103 | 104 | callback_preargs(my_callback_preargs, str); 105 | 106 | callback_postargs(my_callback_postargs, str); 107 | 108 | return exit_status(); 109 | } 110 | -------------------------------------------------------------------------------- /ccan/opt/test/utils.c: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "utils.h" 10 | 11 | unsigned int test_cb_called; 12 | char *test_noarg(void *arg) 13 | { 14 | test_cb_called++; 15 | return NULL; 16 | } 17 | 18 | char *test_arg(const char *optarg, const char *arg) 19 | { 20 | test_cb_called++; 21 | ok1(strcmp(optarg, arg) == 0); 22 | return NULL; 23 | } 24 | 25 | void show_arg(char buf[OPT_SHOW_LEN], const char *arg) 26 | { 27 | strncpy(buf, arg, OPT_SHOW_LEN); 28 | } 29 | 30 | char *err_output = NULL; 31 | 32 | void save_err_output(const char *fmt, ...) 33 | { 34 | va_list ap; 35 | char *p; 36 | 37 | va_start(ap, fmt); 38 | /* Check return, for fascist gcc */ 39 | if (vasprintf(&p, fmt, ap) == -1) 40 | p = NULL; 41 | va_end(ap); 42 | 43 | if (err_output) { 44 | err_output = realloc(err_output, 45 | strlen(err_output) + strlen(p) + 1); 46 | strcat(err_output, p); 47 | free(p); 48 | } else 49 | err_output = p; 50 | } 51 | 52 | static bool allocated = false; 53 | 54 | bool parse_args(int *argc, char ***argv, ...) 55 | { 56 | char **a; 57 | va_list ap; 58 | 59 | va_start(ap, argv); 60 | *argc = 1; 61 | a = malloc(sizeof(*a) * (*argc + 1)); 62 | a[0] = (*argv)[0]; 63 | while ((a[*argc] = va_arg(ap, char *)) != NULL) { 64 | (*argc)++; 65 | a = realloc(a, sizeof(*a) * (*argc + 1)); 66 | } 67 | 68 | if (allocated) 69 | free(*argv); 70 | 71 | *argv = a; 72 | allocated = true; 73 | /* Re-set before parsing. */ 74 | optind = 0; 75 | 76 | return opt_parse(argc, *argv, save_err_output); 77 | } 78 | 79 | struct opt_table short_table[] = { 80 | /* Short opts, different args. */ 81 | OPT_WITHOUT_ARG("-a", test_noarg, "a", "Description of a"), 82 | OPT_WITH_ARG("-b", test_arg, show_arg, "b", "Description of b"), 83 | OPT_ENDTABLE 84 | }; 85 | 86 | struct opt_table long_table[] = { 87 | /* Long opts, different args. */ 88 | OPT_WITHOUT_ARG("--ddd", test_noarg, "ddd", "Description of ddd"), 89 | OPT_WITH_ARG("--eee ", test_arg, show_arg, "eee", ""), 90 | OPT_ENDTABLE 91 | }; 92 | 93 | struct opt_table long_and_short_table[] = { 94 | /* Short and long, different args. */ 95 | OPT_WITHOUT_ARG("--ggg|-g", test_noarg, "ggg", "Description of ggg"), 96 | OPT_WITH_ARG("-h|--hhh", test_arg, NULL, "hhh", "Description of hhh"), 97 | OPT_ENDTABLE 98 | }; 99 | 100 | /* Sub-table test. */ 101 | struct opt_table subtables[] = { 102 | /* Two short, and two long long, no description */ 103 | OPT_WITH_ARG("--jjj|-j|--lll|-l", test_arg, show_arg, "jjj", ""), 104 | /* Hidden option */ 105 | OPT_WITH_ARG("--mmm|-m", test_arg, show_arg, "mmm", opt_hidden), 106 | OPT_SUBTABLE(short_table, NULL), 107 | OPT_SUBTABLE(long_table, "long table options"), 108 | OPT_SUBTABLE(long_and_short_table, NULL), 109 | OPT_ENDTABLE 110 | }; 111 | -------------------------------------------------------------------------------- /sha2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FIPS 180-2 SHA-224/256/384/512 implementation 3 | * Last update: 02/02/2007 4 | * Issue date: 04/30/2005 5 | * 6 | * Copyright (C) 2013, Con Kolivas 7 | * Copyright (C) 2005, 2007 Olivier Gay 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the project nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 | * SUCH DAMAGE. 33 | */ 34 | 35 | #include "config.h" 36 | #include "miner.h" 37 | 38 | #ifndef SHA2_H 39 | #define SHA2_H 40 | 41 | #define SHA256_DIGEST_SIZE ( 256 / 8) 42 | #define SHA256_BLOCK_SIZE ( 512 / 8) 43 | 44 | #define SHFR(x, n) (x >> n) 45 | #define ROTR(x, n) ((x >> n) | (x << ((sizeof(x) << 3) - n))) 46 | #define CH(x, y, z) ((x & y) ^ (~x & z)) 47 | #define MAJ(x, y, z) ((x & y) ^ (x & z) ^ (y & z)) 48 | 49 | #define SHA256_F1(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22)) 50 | #define SHA256_F2(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25)) 51 | #define SHA256_F3(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHFR(x, 3)) 52 | #define SHA256_F4(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHFR(x, 10)) 53 | 54 | typedef struct { 55 | unsigned int tot_len; 56 | unsigned int len; 57 | unsigned char block[2 * SHA256_BLOCK_SIZE]; 58 | uint32_t h[8]; 59 | } sha256_ctx; 60 | 61 | extern uint32_t sha256_k[64]; 62 | 63 | void sha256_init(sha256_ctx * ctx); 64 | void sha256_update(sha256_ctx *ctx, const unsigned char *message, 65 | unsigned int len); 66 | void sha256_final(sha256_ctx *ctx, unsigned char *digest); 67 | void sha256(const unsigned char *message, unsigned int len, 68 | unsigned char *digest); 69 | 70 | #endif /* !SHA2_H */ 71 | -------------------------------------------------------------------------------- /logging.h: -------------------------------------------------------------------------------- 1 | #ifndef __LOGGING_H__ 2 | #define __LOGGING_H__ 3 | 4 | #include "config.h" 5 | #include 6 | #include 7 | 8 | #ifdef HAVE_SYSLOG_H 9 | #include 10 | #else 11 | enum { 12 | LOG_ERR, 13 | LOG_WARNING, 14 | LOG_NOTICE, 15 | LOG_INFO, 16 | LOG_DEBUG, 17 | }; 18 | #endif 19 | 20 | /* debug flags */ 21 | extern bool opt_debug; 22 | extern bool opt_log_output; 23 | extern bool opt_realquiet; 24 | extern bool want_per_device_stats; 25 | 26 | /* global log_level, messages with lower or equal prio are logged */ 27 | extern int opt_log_level; 28 | 29 | #define LOGBUFSIZ 256 30 | 31 | extern void _applog(int prio, const char *str, bool force); 32 | 33 | #define IN_FMT_FFL " in %s %s():%d" 34 | 35 | #define applog(prio, fmt, ...) do { \ 36 | if (opt_debug || prio != LOG_DEBUG) { \ 37 | if (use_syslog || opt_log_output || prio <= opt_log_level) { \ 38 | char tmp42[LOGBUFSIZ]; \ 39 | snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \ 40 | _applog(prio, tmp42, false); \ 41 | } \ 42 | } \ 43 | } while (0) 44 | 45 | #define applogsiz(prio, _SIZ, fmt, ...) do { \ 46 | if (opt_debug || prio != LOG_DEBUG) { \ 47 | if (use_syslog || opt_log_output || prio <= opt_log_level) { \ 48 | char tmp42[_SIZ]; \ 49 | snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \ 50 | _applog(prio, tmp42, false); \ 51 | } \ 52 | } \ 53 | } while (0) 54 | 55 | #define forcelog(prio, fmt, ...) do { \ 56 | if (opt_debug || prio != LOG_DEBUG) { \ 57 | if (use_syslog || opt_log_output || prio <= opt_log_level) { \ 58 | char tmp42[LOGBUFSIZ]; \ 59 | snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \ 60 | _applog(prio, tmp42, true); \ 61 | } \ 62 | } \ 63 | } while (0) 64 | 65 | #define quit(status, fmt, ...) do { \ 66 | if (fmt) { \ 67 | char tmp42[LOGBUFSIZ]; \ 68 | snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \ 69 | _applog(LOG_ERR, tmp42, true); \ 70 | } \ 71 | _quit(status); \ 72 | } while (0) 73 | 74 | #define quithere(status, fmt, ...) do { \ 75 | if (fmt) { \ 76 | char tmp42[LOGBUFSIZ]; \ 77 | snprintf(tmp42, sizeof(tmp42), fmt IN_FMT_FFL, \ 78 | ##__VA_ARGS__, __FILE__, __func__, __LINE__); \ 79 | _applog(LOG_ERR, tmp42, true); \ 80 | } \ 81 | _quit(status); \ 82 | } while (0) 83 | 84 | #define quitfrom(status, _file, _func, _line, fmt, ...) do { \ 85 | if (fmt) { \ 86 | char tmp42[LOGBUFSIZ]; \ 87 | snprintf(tmp42, sizeof(tmp42), fmt IN_FMT_FFL, \ 88 | ##__VA_ARGS__, _file, _func, _line); \ 89 | _applog(LOG_ERR, tmp42, true); \ 90 | } \ 91 | _quit(status); \ 92 | } while (0) 93 | 94 | #ifdef HAVE_CURSES 95 | 96 | #define wlog(fmt, ...) do { \ 97 | char tmp42[LOGBUFSIZ]; \ 98 | snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \ 99 | _wlog(tmp42); \ 100 | } while (0) 101 | 102 | #define wlogprint(fmt, ...) do { \ 103 | char tmp42[LOGBUFSIZ]; \ 104 | snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \ 105 | _wlogprint(tmp42); \ 106 | } while (0) 107 | 108 | #endif 109 | 110 | #endif /* __LOGGING_H__ */ 111 | -------------------------------------------------------------------------------- /mcp2210.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Con Kolivas 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the Free 6 | * Software Foundation; either version 3 of the License, or (at your option) 7 | * any later version. See COPYING for more details. 8 | */ 9 | 10 | #ifndef MCP2210_H 11 | #define MCP2210_H 12 | 13 | #define MCP2210_BUFFER_LENGTH 64 14 | #define MCP2210_TRANSFER_MAX 60 15 | 16 | #define MCP2210_PIN_GPIO 0x0 17 | #define MCP2210_PIN_CS 0x1 18 | #define MCP2210_PIN_DEDICATED 0x2 19 | 20 | #define MCP2210_GPIO_PIN_LOW 0 21 | #define MCP2210_GPIO_PIN_HIGH 1 22 | 23 | #define MCP2210_GPIO_OUTPUT 0 24 | #define MCP2210_GPIO_INPUT 1 25 | 26 | #define MCP2210_SPI_CANCEL 0x11 27 | #define MCP2210_GET_GPIO_SETTING 0x20 28 | #define MCP2210_SET_GPIO_SETTING 0x21 29 | #define MCP2210_SET_GPIO_PIN_VAL 0x30 30 | #define MCP2210_GET_GPIO_PIN_VAL 0x31 31 | #define MCP2210_SET_GPIO_PIN_DIR 0x32 32 | #define MCP2210_GET_GPIO_PIN_DIR 0x33 33 | #define MCP2210_SET_SPI_SETTING 0X40 34 | #define MCP2210_GET_SPI_SETTING 0X41 35 | #define MCP2210_SPI_TRANSFER 0x42 36 | 37 | #define MCP2210_SPI_TRANSFER_SUCCESS 0x00 38 | #define MCP2210_SPI_TRANSFER_ERROR_NA 0xF7 // SPI not available due to external owner 39 | #define MCP2210_SPI_TRANSFER_ERROR_IP 0xF8 // SPI not available due to transfer in progress 40 | 41 | struct gpio_pin { 42 | uint8_t pin[9]; 43 | }; 44 | 45 | struct mcp_settings { 46 | struct gpio_pin designation; 47 | struct gpio_pin value; 48 | struct gpio_pin direction; 49 | unsigned int bitrate, icsv, acsv, cstdd, ldbtcsd, sdbd, bpst, spimode; 50 | }; 51 | 52 | bool mcp2210_send_recv(struct cgpu_info *cgpu, char *buf, enum usb_cmds cmd); 53 | bool mcp2210_get_gpio_settings(struct cgpu_info *cgpu, struct mcp_settings *mcp); 54 | bool mcp2210_set_gpio_settings(struct cgpu_info *cgpu, struct mcp_settings *mcp); 55 | bool mcp2210_get_gpio_pindes(struct cgpu_info *cgpu, struct gpio_pin *gp); 56 | bool mcp2210_get_gpio_pinvals(struct cgpu_info *cgpu, struct gpio_pin *gp); 57 | bool mcp2210_get_gpio_pindirs(struct cgpu_info *cgpu, struct gpio_pin *gp); 58 | bool mcp2210_get_gpio_pin(struct cgpu_info *cgpu, int pin, int *des); 59 | bool mcp2210_get_gpio_pinval(struct cgpu_info *cgpu, int pin, int *val); 60 | bool mcp2210_get_gpio_pindir(struct cgpu_info *cgpu, int pin, int *dir); 61 | bool mcp2210_spi_cancel(struct cgpu_info *cgpu); 62 | bool 63 | mcp2210_get_spi_transfer_settings(struct cgpu_info *cgpu, unsigned int *bitrate, unsigned int *icsv, 64 | unsigned int *acsv, unsigned int *cstdd, unsigned int *ldbtcsd, 65 | unsigned int *sdbd, unsigned int *bpst, unsigned int *spimode); 66 | bool 67 | mcp2210_set_spi_transfer_settings(struct cgpu_info *cgpu, unsigned int bitrate, unsigned int icsv, 68 | unsigned int acsv, unsigned int cstdd, unsigned int ldbtcsd, 69 | unsigned int sdbd, unsigned int bpst, unsigned int spimode); 70 | bool mcp2210_spi_transfer(struct cgpu_info *cgpu, struct mcp_settings *mcp, 71 | char *data, unsigned int *length); 72 | 73 | #endif /* MCP2210_H */ 74 | -------------------------------------------------------------------------------- /lib/stddef.in.h: -------------------------------------------------------------------------------- 1 | /* A substitute for POSIX 2008 , for platforms that have issues. 2 | 3 | Copyright (C) 2009-2011 Free Software Foundation, Inc. 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3, or (at your option) 8 | any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software Foundation, 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 18 | 19 | /* Written by Eric Blake. */ 20 | 21 | /* 22 | * POSIX 2008 for platforms that have issues. 23 | * 24 | */ 25 | 26 | #if __GNUC__ >= 3 27 | @PRAGMA_SYSTEM_HEADER@ 28 | #endif 29 | @PRAGMA_COLUMNS@ 30 | 31 | #if defined __need_wchar_t || defined __need_size_t \ 32 | || defined __need_ptrdiff_t || defined __need_NULL \ 33 | || defined __need_wint_t 34 | /* Special invocation convention inside gcc header files. In 35 | particular, gcc provides a version of that blindly 36 | redefines NULL even when __need_wint_t was defined, even though 37 | wint_t is not normally provided by . Hence, we must 38 | remember if special invocation has ever been used to obtain wint_t, 39 | in which case we need to clean up NULL yet again. */ 40 | 41 | # if !(defined _@GUARD_PREFIX@_STDDEF_H && defined _GL_STDDEF_WINT_T) 42 | # ifdef __need_wint_t 43 | # undef _@GUARD_PREFIX@_STDDEF_H 44 | # define _GL_STDDEF_WINT_T 45 | # endif 46 | # @INCLUDE_NEXT@ @NEXT_STDDEF_H@ 47 | # endif 48 | 49 | #else 50 | /* Normal invocation convention. */ 51 | 52 | # ifndef _@GUARD_PREFIX@_STDDEF_H 53 | 54 | /* The include_next requires a split double-inclusion guard. */ 55 | 56 | # @INCLUDE_NEXT@ @NEXT_STDDEF_H@ 57 | 58 | # ifndef _@GUARD_PREFIX@_STDDEF_H 59 | # define _@GUARD_PREFIX@_STDDEF_H 60 | 61 | /* On NetBSD 5.0, the definition of NULL lacks proper parentheses. */ 62 | #if @REPLACE_NULL@ 63 | # undef NULL 64 | # ifdef __cplusplus 65 | /* ISO C++ says that the macro NULL must expand to an integer constant 66 | expression, hence '((void *) 0)' is not allowed in C++. */ 67 | # if __GNUG__ >= 3 68 | /* GNU C++ has a __null macro that behaves like an integer ('int' or 69 | 'long') but has the same size as a pointer. Use that, to avoid 70 | warnings. */ 71 | # define NULL __null 72 | # else 73 | # define NULL 0L 74 | # endif 75 | # else 76 | # define NULL ((void *) 0) 77 | # endif 78 | #endif 79 | 80 | /* Some platforms lack wchar_t. */ 81 | #if !@HAVE_WCHAR_T@ 82 | # define wchar_t int 83 | #endif 84 | 85 | # endif /* _@GUARD_PREFIX@_STDDEF_H */ 86 | # endif /* _@GUARD_PREFIX@_STDDEF_H */ 87 | #endif /* __need_XXX */ 88 | -------------------------------------------------------------------------------- /m4/memchr.m4: -------------------------------------------------------------------------------- 1 | # memchr.m4 serial 12 2 | dnl Copyright (C) 2002-2004, 2009-2011 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | AC_DEFUN_ONCE([gl_FUNC_MEMCHR], 8 | [ 9 | dnl Check for prerequisites for memory fence checks. 10 | gl_FUNC_MMAP_ANON 11 | AC_CHECK_HEADERS_ONCE([sys/mman.h]) 12 | AC_CHECK_FUNCS_ONCE([mprotect]) 13 | 14 | AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) 15 | m4_ifdef([gl_FUNC_MEMCHR_OBSOLETE], [ 16 | dnl These days, we assume memchr is present. But if support for old 17 | dnl platforms is desired: 18 | AC_CHECK_FUNCS_ONCE([memchr]) 19 | if test $ac_cv_func_memchr = no; then 20 | HAVE_MEMCHR=0 21 | fi 22 | ]) 23 | if test $HAVE_MEMCHR = 1; then 24 | # Detect platform-specific bugs in some versions of glibc: 25 | # memchr should not dereference anything with length 0 26 | # http://bugzilla.redhat.com/499689 27 | # memchr should not dereference overestimated length after a match 28 | # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=521737 29 | # http://sourceware.org/bugzilla/show_bug.cgi?id=10162 30 | # Assume that memchr works on platforms that lack mprotect. 31 | AC_CACHE_CHECK([whether memchr works], [gl_cv_func_memchr_works], 32 | [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ 33 | #include 34 | #if HAVE_SYS_MMAN_H 35 | # include 36 | # include 37 | # include 38 | # include 39 | # ifndef MAP_FILE 40 | # define MAP_FILE 0 41 | # endif 42 | #endif 43 | ]], [[ 44 | int result = 0; 45 | char *fence = NULL; 46 | #if HAVE_SYS_MMAN_H && HAVE_MPROTECT 47 | # if HAVE_MAP_ANONYMOUS 48 | const int flags = MAP_ANONYMOUS | MAP_PRIVATE; 49 | const int fd = -1; 50 | # else /* !HAVE_MAP_ANONYMOUS */ 51 | const int flags = MAP_FILE | MAP_PRIVATE; 52 | int fd = open ("/dev/zero", O_RDONLY, 0666); 53 | if (fd >= 0) 54 | # endif 55 | { 56 | int pagesize = getpagesize (); 57 | char *two_pages = 58 | (char *) mmap (NULL, 2 * pagesize, PROT_READ | PROT_WRITE, 59 | flags, fd, 0); 60 | if (two_pages != (char *)(-1) 61 | && mprotect (two_pages + pagesize, pagesize, PROT_NONE) == 0) 62 | fence = two_pages + pagesize; 63 | } 64 | #endif 65 | if (fence) 66 | { 67 | if (memchr (fence, 0, 0)) 68 | result |= 1; 69 | strcpy (fence - 9, "12345678"); 70 | if (memchr (fence - 9, 0, 79) != fence - 1) 71 | result |= 2; 72 | if (memchr (fence - 1, 0, 3) != fence - 1) 73 | result |= 4; 74 | } 75 | return result; 76 | ]])], [gl_cv_func_memchr_works=yes], [gl_cv_func_memchr_works=no], 77 | [dnl Be pessimistic for now. 78 | gl_cv_func_memchr_works="guessing no"])]) 79 | if test "$gl_cv_func_memchr_works" != yes; then 80 | REPLACE_MEMCHR=1 81 | fi 82 | fi 83 | ]) 84 | 85 | # Prerequisites of lib/memchr.c. 86 | AC_DEFUN([gl_PREREQ_MEMCHR], [ 87 | AC_CHECK_HEADERS([bp-sym.h]) 88 | ]) 89 | -------------------------------------------------------------------------------- /lib/memmem.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 1991-1994, 1996-1998, 2000, 2004, 2007-2011 Free Software 2 | Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3, or (at your option) 8 | any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License along 16 | with this program; if not, write to the Free Software Foundation, 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 18 | 19 | /* This particular implementation was written by Eric Blake, 2008. */ 20 | 21 | #ifndef _LIBC 22 | # include 23 | #endif 24 | 25 | /* Specification of memmem. */ 26 | #include 27 | 28 | #ifndef _LIBC 29 | # define __builtin_expect(expr, val) (expr) 30 | #endif 31 | 32 | #define RETURN_TYPE void * 33 | #define AVAILABLE(h, h_l, j, n_l) ((j) <= (h_l) - (n_l)) 34 | #include "str-two-way.h" 35 | 36 | /* Return the first occurrence of NEEDLE in HAYSTACK. Return HAYSTACK 37 | if NEEDLE_LEN is 0, otherwise NULL if NEEDLE is not found in 38 | HAYSTACK. */ 39 | void * 40 | memmem (const void *haystack_start, size_t haystack_len, 41 | const void *needle_start, size_t needle_len) 42 | { 43 | /* Abstract memory is considered to be an array of 'unsigned char' values, 44 | not an array of 'char' values. See ISO C 99 section 6.2.6.1. */ 45 | const unsigned char *haystack = (const unsigned char *) haystack_start; 46 | const unsigned char *needle = (const unsigned char *) needle_start; 47 | 48 | if (needle_len == 0) 49 | /* The first occurrence of the empty string is deemed to occur at 50 | the beginning of the string. */ 51 | return (void *) haystack; 52 | 53 | /* Sanity check, otherwise the loop might search through the whole 54 | memory. */ 55 | if (__builtin_expect (haystack_len < needle_len, 0)) 56 | return NULL; 57 | 58 | /* Use optimizations in memchr when possible, to reduce the search 59 | size of haystack using a linear algorithm with a smaller 60 | coefficient. However, avoid memchr for long needles, since we 61 | can often achieve sublinear performance. */ 62 | if (needle_len < LONG_NEEDLE_THRESHOLD) 63 | { 64 | haystack = memchr (haystack, *needle, haystack_len); 65 | if (!haystack || __builtin_expect (needle_len == 1, 0)) 66 | return (void *) haystack; 67 | haystack_len -= haystack - (const unsigned char *) haystack_start; 68 | if (haystack_len < needle_len) 69 | return NULL; 70 | return two_way_short_needle (haystack, haystack_len, needle, needle_len); 71 | } 72 | else 73 | return two_way_long_needle (haystack, haystack_len, needle, needle_len); 74 | } 75 | 76 | #undef LONG_NEEDLE_THRESHOLD 77 | -------------------------------------------------------------------------------- /compat/libusb-1.0/libusb/os/threads_windows.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libusb synchronization on Microsoft Windows 3 | * 4 | * Copyright (C) 2010 Michael Plante 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef LIBUSB_THREADS_WINDOWS_H 22 | #define LIBUSB_THREADS_WINDOWS_H 23 | 24 | #include 25 | 26 | #define usbi_mutex_static_t volatile LONG 27 | #define USBI_MUTEX_INITIALIZER 0 28 | 29 | #define usbi_mutex_t HANDLE 30 | 31 | struct usbi_cond_perthread { 32 | struct list_head list; 33 | DWORD tid; 34 | HANDLE event; 35 | }; 36 | struct usbi_cond_t_ { 37 | // Every time a thread touches the CV, it winds up in one of these lists. 38 | // It stays there until the CV is destroyed, even if the thread 39 | // terminates. 40 | struct list_head waiters; 41 | struct list_head not_waiting; 42 | }; 43 | typedef struct usbi_cond_t_ usbi_cond_t; 44 | 45 | // We *were* getting timespec from pthread.h: 46 | #if (!defined(HAVE_STRUCT_TIMESPEC) && !defined(_TIMESPEC_DEFINED)) 47 | #define HAVE_STRUCT_TIMESPEC 1 48 | #define _TIMESPEC_DEFINED 1 49 | struct timespec { 50 | long tv_sec; 51 | long tv_nsec; 52 | }; 53 | #endif /* HAVE_STRUCT_TIMESPEC | _TIMESPEC_DEFINED */ 54 | 55 | // We *were* getting ETIMEDOUT from pthread.h: 56 | #ifndef ETIMEDOUT 57 | # define ETIMEDOUT 10060 /* This is the value in winsock.h. */ 58 | #endif 59 | 60 | #define usbi_mutexattr_t void 61 | #define usbi_condattr_t void 62 | 63 | // all Windows mutexes are recursive 64 | #define usbi_mutex_init_recursive(mutex, attr) usbi_mutex_init((mutex), (attr)) 65 | 66 | int usbi_mutex_static_lock(usbi_mutex_static_t *mutex); 67 | int usbi_mutex_static_unlock(usbi_mutex_static_t *mutex); 68 | 69 | 70 | int usbi_mutex_init(usbi_mutex_t *mutex, 71 | const usbi_mutexattr_t *attr); 72 | int usbi_mutex_lock(usbi_mutex_t *mutex); 73 | int usbi_mutex_unlock(usbi_mutex_t *mutex); 74 | int usbi_mutex_trylock(usbi_mutex_t *mutex); 75 | int usbi_mutex_destroy(usbi_mutex_t *mutex); 76 | 77 | int usbi_cond_init(usbi_cond_t *cond, 78 | const usbi_condattr_t *attr); 79 | int usbi_cond_destroy(usbi_cond_t *cond); 80 | int usbi_cond_wait(usbi_cond_t *cond, usbi_mutex_t *mutex); 81 | int usbi_cond_timedwait(usbi_cond_t *cond, 82 | usbi_mutex_t *mutex, 83 | const struct timespec *abstime); 84 | int usbi_cond_broadcast(usbi_cond_t *cond); 85 | int usbi_cond_signal(usbi_cond_t *cond); 86 | 87 | #endif /* LIBUSB_THREADS_WINDOWS_H */ 88 | 89 | -------------------------------------------------------------------------------- /ccan/opt/usage.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "private.h" 7 | 8 | /* We only use this for pointer comparisons. */ 9 | const char opt_hidden[1]; 10 | 11 | static unsigned write_short_options(char *str) 12 | { 13 | unsigned int i, num = 0; 14 | const char *p; 15 | 16 | for (p = first_sopt(&i); p; p = next_sopt(p, &i)) { 17 | if (opt_table[i].desc != opt_hidden) 18 | str[num++] = *p; 19 | } 20 | return num; 21 | } 22 | 23 | #define OPT_SPACE_PAD " " 24 | 25 | /* FIXME: Get all purdy. */ 26 | char *opt_usage(const char *argv0, const char *extra) 27 | { 28 | unsigned int i, num, len; 29 | char *ret, *p; 30 | 31 | if (!extra) { 32 | extra = ""; 33 | for (i = 0; i < opt_count; i++) { 34 | if (opt_table[i].cb == (void *)opt_usage_and_exit 35 | && opt_table[i].u.carg) { 36 | extra = opt_table[i].u.carg; 37 | break; 38 | } 39 | } 40 | } 41 | 42 | /* An overestimate of our length. */ 43 | len = strlen("Usage: %s ") + strlen(argv0) 44 | + strlen("[-%.*s]") + opt_num_short + 1 45 | + strlen(" ") + strlen(extra) 46 | + strlen("\n"); 47 | 48 | for (i = 0; i < opt_count; i++) { 49 | if (opt_table[i].type == OPT_SUBTABLE) { 50 | len += strlen("\n") + strlen(opt_table[i].desc) 51 | + strlen(":\n"); 52 | } else if (opt_table[i].desc != opt_hidden) { 53 | len += strlen(opt_table[i].names) + strlen(" "); 54 | len += strlen(OPT_SPACE_PAD) 55 | + strlen(opt_table[i].desc) + 1; 56 | if (opt_table[i].show) { 57 | len += strlen("(default: %s)") 58 | + OPT_SHOW_LEN + sizeof("..."); 59 | } 60 | len += strlen("\n"); 61 | } 62 | } 63 | 64 | p = ret = malloc(len); 65 | if (!ret) 66 | return NULL; 67 | 68 | p += sprintf(p, "Usage: %s", argv0); 69 | p += sprintf(p, " [-"); 70 | num = write_short_options(p); 71 | if (num) { 72 | p += num; 73 | p += sprintf(p, "]"); 74 | } else { 75 | /* Remove start of single-entry options */ 76 | p -= 3; 77 | } 78 | if (extra) 79 | p += sprintf(p, " %s", extra); 80 | p += sprintf(p, "\n"); 81 | 82 | for (i = 0; i < opt_count; i++) { 83 | if (opt_table[i].desc == opt_hidden) 84 | continue; 85 | if (opt_table[i].type == OPT_SUBTABLE) { 86 | p += sprintf(p, "%s:\n", opt_table[i].desc); 87 | continue; 88 | } 89 | len = sprintf(p, "%s", opt_table[i].names); 90 | if (opt_table[i].type == OPT_HASARG 91 | && !strchr(opt_table[i].names, ' ') 92 | && !strchr(opt_table[i].names, '=')) 93 | len += sprintf(p + len, " "); 94 | len += sprintf(p + len, "%.*s", 95 | len < strlen(OPT_SPACE_PAD) 96 | ? (unsigned)strlen(OPT_SPACE_PAD) - len : 1, 97 | OPT_SPACE_PAD); 98 | 99 | len += sprintf(p + len, "%s", opt_table[i].desc); 100 | if (opt_table[i].show) { 101 | char buf[OPT_SHOW_LEN + sizeof("...")]; 102 | strcpy(buf + OPT_SHOW_LEN, "..."); 103 | opt_table[i].show(buf, opt_table[i].u.arg); 104 | len += sprintf(p + len, " (default: %s)", buf); 105 | } 106 | p += len; 107 | p += sprintf(p, "\n"); 108 | } 109 | *p = '\0'; 110 | return ret; 111 | } 112 | -------------------------------------------------------------------------------- /compat/jansson-2.5/src/strbuffer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2013 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef _GNU_SOURCE 9 | #define _GNU_SOURCE 10 | #endif 11 | 12 | #include 13 | #include 14 | #include "jansson_private.h" 15 | #include "strbuffer.h" 16 | 17 | #define STRBUFFER_MIN_SIZE 16 18 | #define STRBUFFER_FACTOR 2 19 | #define STRBUFFER_SIZE_MAX ((size_t)-1) 20 | 21 | int strbuffer_init(strbuffer_t *strbuff) 22 | { 23 | strbuff->size = STRBUFFER_MIN_SIZE; 24 | strbuff->length = 0; 25 | 26 | strbuff->value = jsonp_malloc(strbuff->size); 27 | if(!strbuff->value) 28 | return -1; 29 | 30 | /* initialize to empty */ 31 | strbuff->value[0] = '\0'; 32 | return 0; 33 | } 34 | 35 | void strbuffer_close(strbuffer_t *strbuff) 36 | { 37 | if(strbuff->value) 38 | jsonp_free(strbuff->value); 39 | 40 | strbuff->size = 0; 41 | strbuff->length = 0; 42 | strbuff->value = NULL; 43 | } 44 | 45 | void strbuffer_clear(strbuffer_t *strbuff) 46 | { 47 | strbuff->length = 0; 48 | strbuff->value[0] = '\0'; 49 | } 50 | 51 | const char *strbuffer_value(const strbuffer_t *strbuff) 52 | { 53 | return strbuff->value; 54 | } 55 | 56 | char *strbuffer_steal_value(strbuffer_t *strbuff) 57 | { 58 | char *result = strbuff->value; 59 | strbuff->value = NULL; 60 | return result; 61 | } 62 | 63 | int strbuffer_append(strbuffer_t *strbuff, const char *string) 64 | { 65 | return strbuffer_append_bytes(strbuff, string, strlen(string)); 66 | } 67 | 68 | int strbuffer_append_byte(strbuffer_t *strbuff, char byte) 69 | { 70 | return strbuffer_append_bytes(strbuff, &byte, 1); 71 | } 72 | 73 | int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size) 74 | { 75 | if(size >= strbuff->size - strbuff->length) 76 | { 77 | size_t new_size; 78 | char *new_value; 79 | 80 | /* avoid integer overflow */ 81 | if (strbuff->size > STRBUFFER_SIZE_MAX / STRBUFFER_FACTOR 82 | || size > STRBUFFER_SIZE_MAX - 1 83 | || strbuff->length > STRBUFFER_SIZE_MAX - 1 - size) 84 | return -1; 85 | 86 | new_size = max(strbuff->size * STRBUFFER_FACTOR, 87 | strbuff->length + size + 1); 88 | 89 | new_value = jsonp_malloc(new_size); 90 | if(!new_value) 91 | return -1; 92 | 93 | memcpy(new_value, strbuff->value, strbuff->length); 94 | 95 | jsonp_free(strbuff->value); 96 | strbuff->value = new_value; 97 | strbuff->size = new_size; 98 | } 99 | 100 | memcpy(strbuff->value + strbuff->length, data, size); 101 | strbuff->length += size; 102 | strbuff->value[strbuff->length] = '\0'; 103 | 104 | return 0; 105 | } 106 | 107 | char strbuffer_pop(strbuffer_t *strbuff) 108 | { 109 | if(strbuff->length > 0) { 110 | char c = strbuff->value[--strbuff->length]; 111 | strbuff->value[strbuff->length] = '\0'; 112 | return c; 113 | } 114 | else 115 | return '\0'; 116 | } 117 | -------------------------------------------------------------------------------- /fpgautils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Luke Dashjr 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the Free 6 | * Software Foundation; either version 3 of the License, or (at your option) 7 | * any later version. See COPYING for more details. 8 | */ 9 | 10 | #ifndef FPGAUTILS_H 11 | #define FPGAUTILS_H 12 | 13 | #include 14 | #include 15 | 16 | typedef bool(*detectone_func_t)(const char*); 17 | typedef int(*autoscan_func_t)(); 18 | 19 | extern int _serial_detect(struct device_drv *drv, detectone_func_t, autoscan_func_t, bool force_autoscan); 20 | #define serial_detect_fauto(drv, detectone, autoscan) \ 21 | _serial_detect(drv, detectone, autoscan, true) 22 | #define serial_detect_auto(drv, detectone, autoscan) \ 23 | _serial_detect(drv, detectone, autoscan, false) 24 | #define serial_detect(drv, detectone) \ 25 | _serial_detect(drv, detectone, NULL, false) 26 | extern int serial_autodetect_devserial(detectone_func_t, const char *prodname); 27 | extern int serial_autodetect_udev(detectone_func_t, const char *prodname); 28 | 29 | extern int serial_open(const char *devpath, unsigned long baud, signed short timeout, bool purge); 30 | extern ssize_t _serial_read(int fd, char *buf, size_t buflen, char *eol); 31 | #define serial_read(fd, buf, count) \ 32 | _serial_read(fd, (char*)(buf), count, NULL) 33 | #define serial_read_line(fd, buf, bufsiz, eol) \ 34 | _serial_read(fd, buf, bufsiz, &eol) 35 | #define serial_close(fd) close(fd) 36 | 37 | extern FILE *open_bitstream(const char *dname, const char *filename); 38 | 39 | extern int get_serial_cts(int fd); 40 | 41 | #ifndef WIN32 42 | extern const struct timeval tv_timeout_default; 43 | extern const struct timeval tv_inter_char_default; 44 | 45 | extern size_t _select_read(int fd, char *buf, size_t bufsiz, struct timeval *timeout, struct timeval *char_timeout, int finished); 46 | extern size_t _select_write(int fd, char *buf, size_t siz, struct timeval *timeout); 47 | 48 | #define select_open(devpath) \ 49 | serial_open(devpath, 0, 0, false) 50 | 51 | #define select_open_purge(devpath, purge)\ 52 | serial_open(devpath, 0, 0, purge) 53 | 54 | #define select_write(fd, buf, siz) \ 55 | _select_write(fd, buf, siz, (struct timeval *)(&tv_timeout_default)) 56 | 57 | #define select_write_full _select_write 58 | 59 | #define select_read(fd, buf, bufsiz) \ 60 | _select_read(fd, buf, bufsiz, (struct timeval *)(&tv_timeout_default), \ 61 | (struct timeval *)(&tv_inter_char_default), -1) 62 | 63 | #define select_read_til(fd, buf, bufsiz, eol) \ 64 | _select_read(fd, buf, bufsiz, (struct timeval *)(&tv_timeout_default), \ 65 | (struct timeval *)(&tv_inter_char_default), eol) 66 | 67 | #define select_read_wait(fd, buf, bufsiz, timeout) \ 68 | _select_read(fd, buf, bufsiz, timeout, \ 69 | (struct timeval *)(&tv_inter_char_default), -1) 70 | 71 | #define select_read_wait_til(fd, buf, bufsiz, timeout, eol) \ 72 | _select_read(fd, buf, bufsiz, timeout, \ 73 | (struct timeval *)(&tv_inter_char_default), eol) 74 | 75 | #define select_read_wait_both(fd, buf, bufsiz, timeout, char_timeout) \ 76 | _select_read(fd, buf, bufsiz, timeout, char_timeout, -1) 77 | 78 | #define select_read_full _select_read 79 | 80 | #define select_close(fd) close(fd) 81 | 82 | #endif // ! WIN32 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /usbtest.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python2.7 2 | # 3 | # Original version supplied to me (Kano/kanoi) by xiangfu 4 | # 5 | # Modified to allow supplying the data to send 6 | # 7 | # Linux usAge: ./ubstest.py /dev/ttyUSB0 0xhexcodes|string|icarus 8 | # OR python ubstest.py /dev/ttyUSB0 0xhexcodes|string|icarus 9 | # 10 | # Windows usAge: ./ubstest.py COM1 0xhexcodes|string|icarus 11 | # 12 | # sends the data sepcified to the USB device and waits 13 | # for a reply then displays it 14 | # 15 | # the data can be: 16 | # 0xhexcodes: e.g. 0x68656c6c6f20776f726c640a 17 | # would send "hello world\n" 18 | # 19 | # string: e.g. sendsometext 20 | # 21 | # icarus: sends 2 known block payloads for an icarus device 22 | # and shows the expected and actual answers if it's 23 | # a working V3 icarus 24 | 25 | import sys 26 | import serial 27 | import binascii 28 | 29 | if len(sys.argv) < 2: 30 | sys.stderr.write("usAge: " + sys.argv[0] + " device strings...\n") 31 | sys.stderr.write(" where device is either like /dev/ttyUSB0 or COM1\n") 32 | sys.stderr.write(" and strings are either '0xXXXX' or 'text'\n") 33 | sys.stderr.write(" if the first string is 'icarus' the rest are ignored\n") 34 | sys.stderr.write(" and 2 valid icarus test payloads are sent with results displayed\n") 35 | sys.stderr.write("\nAfter any command is sent it waits up to 30 seconds for a reply\n"); 36 | sys.exit("Aborting") 37 | 38 | # Open with a 10 second timeout - just to be sure 39 | ser = serial.Serial(sys.argv[1], 115200, serial.EIGHTBITS, serial.PARITY_NONE, serial.STOPBITS_ONE, 10, False, False, 5, False, None) 40 | 41 | if sys.argv[2] == "icarus": 42 | 43 | # This show how Icarus use the block and midstate data 44 | # This will produce nonce 063c5e01 45 | block = "0000000120c8222d0497a7ab44a1a2c7bf39de941c9970b1dc7cdc400000079700000000e88aabe1f353238c668d8a4df9318e614c10c474f8cdf8bc5f6397b946c33d7c4e7242c31a098ea500000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000" 46 | midstate = "33c5bf5751ec7f7e056443b5aee3800331432c83f404d9de38b94ecbf907b92d" 47 | 48 | rdata2 = block.decode('hex')[95:63:-1] 49 | rmid = midstate.decode('hex')[::-1] 50 | payload = rmid + rdata2 51 | 52 | print("Push payload to icarus: " + binascii.hexlify(payload)) 53 | ser.write(payload) 54 | 55 | b=ser.read(4) 56 | print("Result:(should be: 063c5e01): " + binascii.hexlify(b)) 57 | 58 | # Just another test 59 | payload2 = "ce92099c5a80bb81c52990d5c0924c625fd25a535640607d5a4bdf8174e2c8d500000000000000000000000080000000000000000b290c1a42313b4f21b5bcb8" 60 | print("Push payload to icarus: " + payload2) 61 | ser.write(payload2.decode('hex')) 62 | 63 | b=ser.read(4) 64 | print("Result:(should be: 8e0b31c5): " + binascii.hexlify(b)) 65 | else: 66 | data = "" 67 | for arg in sys.argv[2::]: 68 | if arg[0:2:] == '0x': 69 | data += arg[2::].decode('hex') 70 | else: 71 | data += arg 72 | 73 | print("Sending: 0x" + binascii.hexlify(data)) 74 | ser.write(data) 75 | 76 | # If you're expecting more than one linefeed terminated reply, 77 | # you'll only see the first one 78 | # AND with no linefeed, this will wait the 10 seconds before returning 79 | print("Waiting up to 10 seconds ...") 80 | b=ser.readline() 81 | print("Result: hex 0x" + binascii.hexlify(b)) 82 | 83 | # This could mess up the display - do it last 84 | print("Result: asc '" + b + "'") 85 | 86 | ser.close() 87 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | ACLOCAL_AMFLAGS = -I m4 3 | 4 | JANSSON_CPPFLAGS= -I$(top_builddir)/compat/jansson-2.5/src -I$(top_srcdir)/compat/jansson-2.5/src 5 | 6 | if WANT_USBUTILS 7 | USBUTILS_CPPFLAGS = -I$(top_builddir)/compat/libusb-1.0/libusb -I$(top_srcdir)/compat/libusb-1.0/libusb 8 | else 9 | USBUTILS_CPPFLAGS = 10 | endif 11 | 12 | EXTRA_DIST = example.conf linux-usb-cgminer \ 13 | api-example.php miner.php \ 14 | API.class API.java api-example.c windows-build.txt \ 15 | bitstreams/* API-README FPGA-README \ 16 | bitforce-firmware-flash.c hexdump.c ASIC-README \ 17 | ADL_SDK/readme.txt SCRYPT-README GPU-README \ 18 | 01-cgminer.rules 19 | 20 | SUBDIRS = lib compat ccan 21 | 22 | cgminer_CPPFLAGS = $(PTHREAD_FLAGS) -fno-strict-aliasing $(JANSSON_CPPFLAGS) $(USBUTILS_CPPFLAGS) 23 | 24 | bin_PROGRAMS = cgminer 25 | 26 | cgminer_LDFLAGS = $(PTHREAD_FLAGS) 27 | cgminer_LDADD = $(DLOPEN_FLAGS) @LIBCURL_LIBS@ @JANSSON_LIBS@ @PTHREAD_LIBS@ \ 28 | @NCURSES_LIBS@ @PDCURSES_LIBS@ @WS2_LIBS@ \ 29 | @LIBUSB_LIBS@ @MM_LIBS@ @RT_LIBS@ \ 30 | @MATH_LIBS@ lib/libgnu.a ccan/libccan.a 31 | 32 | cgminer_CPPFLAGS += -I$(top_builddir)/lib -I$(top_srcdir)/lib 33 | 34 | if !HAVE_WINDOWS 35 | cgminer_CPPFLAGS += @LIBCURL_CFLAGS@ 36 | endif 37 | 38 | # common sources 39 | cgminer_SOURCES := cgminer.c 40 | 41 | cgminer_SOURCES += elist.h miner.h compat.h bench_block.h \ 42 | util.c util.h uthash.h logging.h \ 43 | sha2.c sha2.h api.c 44 | 45 | cgminer_SOURCES += logging.c 46 | 47 | if HAS_OPENCL 48 | bin_SCRIPTS = $(top_srcdir)/*.cl 49 | 50 | cgminer_SOURCES += driver-opencl.h driver-opencl.c 51 | cgminer_SOURCES += ocl.c ocl.h 52 | cgminer_SOURCES += adl.c adl.h adl_functions.h 53 | cgminer_SOURCES += *.cl 54 | cgminer_LDADD += @OPENCL_LIBS@ 55 | cgminer_CPPFLAGS += @OPENCL_FLAGS@ 56 | cgminer_CPPFLAGS += $(ADL_CPPFLAGS) 57 | 58 | if HAS_SCRYPT 59 | cgminer_SOURCES += scrypt.c scrypt.h 60 | endif 61 | 62 | endif 63 | 64 | cgminer_SOURCES += klist.h klist.c 65 | 66 | if NEED_FPGAUTILS 67 | cgminer_SOURCES += fpgautils.c fpgautils.h 68 | endif 69 | 70 | if WANT_USBUTILS 71 | cgminer_SOURCES += usbutils.c usbutils.h 72 | endif 73 | 74 | if WANT_LIBBITFURY 75 | cgminer_SOURCES += libbitfury.c libbitfury.h mcp2210.c mcp2210.h 76 | endif 77 | 78 | # Device drivers 79 | if HAS_AVALON 80 | cgminer_SOURCES += driver-avalon.c driver-avalon.h 81 | endif 82 | 83 | if HAS_KNC 84 | cgminer_SOURCES += driver-knc-spi-fpga.c 85 | endif 86 | 87 | if HAS_BFLSC 88 | cgminer_SOURCES += driver-bflsc.c driver-bflsc.h 89 | endif 90 | 91 | if HAS_BITFORCE 92 | cgminer_SOURCES += driver-bitforce.c 93 | endif 94 | 95 | if HAS_HASHFAST 96 | cgminer_SOURCES += driver-hashfast.c driver-hashfast.h hf_protocol.h hf_protocol_be.h 97 | endif 98 | 99 | if HAS_BITFURY 100 | cgminer_SOURCES += driver-bitfury.c driver-bitfury.h 101 | endif 102 | 103 | if HAS_DRILLBIT 104 | cgminer_SOURCES += driver-drillbit.c driver-drillbit.h 105 | endif 106 | 107 | if HAS_ICARUS 108 | cgminer_SOURCES += driver-icarus.c 109 | endif 110 | 111 | if HAS_KLONDIKE 112 | cgminer_SOURCES += driver-klondike.c 113 | endif 114 | 115 | if HAS_BAB 116 | cgminer_SOURCES += driver-bab.c 117 | endif 118 | 119 | if HAS_MINION 120 | cgminer_SOURCES += driver-minion.c 121 | endif 122 | 123 | if HAS_MODMINER 124 | cgminer_SOURCES += driver-modminer.c 125 | bitstreamsdir = $(bindir)/bitstreams 126 | dist_bitstreams_DATA = $(top_srcdir)/bitstreams/* 127 | endif 128 | -------------------------------------------------------------------------------- /compat/jansson-2.5/src/strconv.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "jansson_private.h" 6 | #include "strbuffer.h" 7 | 8 | /* need config.h to get the correct snprintf */ 9 | #ifdef HAVE_CONFIG_H 10 | #include 11 | #endif 12 | 13 | #if JSON_HAVE_LOCALECONV 14 | #include 15 | 16 | /* 17 | - This code assumes that the decimal separator is exactly one 18 | character. 19 | 20 | - If setlocale() is called by another thread between the call to 21 | localeconv() and the call to sprintf() or strtod(), the result may 22 | be wrong. setlocale() is not thread-safe and should not be used 23 | this way. Multi-threaded programs should use uselocale() instead. 24 | */ 25 | 26 | static void to_locale(strbuffer_t *strbuffer) 27 | { 28 | const char *point; 29 | char *pos; 30 | 31 | point = localeconv()->decimal_point; 32 | if(*point == '.') { 33 | /* No conversion needed */ 34 | return; 35 | } 36 | 37 | pos = strchr(strbuffer->value, '.'); 38 | if(pos) 39 | *pos = *point; 40 | } 41 | 42 | static void from_locale(char *buffer) 43 | { 44 | const char *point; 45 | char *pos; 46 | 47 | point = localeconv()->decimal_point; 48 | if(*point == '.') { 49 | /* No conversion needed */ 50 | return; 51 | } 52 | 53 | pos = strchr(buffer, *point); 54 | if(pos) 55 | *pos = '.'; 56 | } 57 | #endif 58 | 59 | int jsonp_strtod(strbuffer_t *strbuffer, double *out) 60 | { 61 | double value; 62 | char *end; 63 | 64 | #if JSON_HAVE_LOCALECONV 65 | to_locale(strbuffer); 66 | #endif 67 | 68 | errno = 0; 69 | value = strtod(strbuffer->value, &end); 70 | assert(end == strbuffer->value + strbuffer->length); 71 | 72 | if(errno == ERANGE && value != 0) { 73 | /* Overflow */ 74 | return -1; 75 | } 76 | 77 | *out = value; 78 | return 0; 79 | } 80 | 81 | int jsonp_dtostr(char *buffer, size_t size, double value) 82 | { 83 | int ret; 84 | char *start, *end; 85 | size_t length; 86 | 87 | ret = snprintf(buffer, size, "%.17g", value); 88 | if(ret < 0) 89 | return -1; 90 | 91 | length = (size_t)ret; 92 | if(length >= size) 93 | return -1; 94 | 95 | #if JSON_HAVE_LOCALECONV 96 | from_locale(buffer); 97 | #endif 98 | 99 | /* Make sure there's a dot or 'e' in the output. Otherwise 100 | a real is converted to an integer when decoding */ 101 | if(strchr(buffer, '.') == NULL && 102 | strchr(buffer, 'e') == NULL) 103 | { 104 | if(length + 3 >= size) { 105 | /* No space to append ".0" */ 106 | return -1; 107 | } 108 | buffer[length] = '.'; 109 | buffer[length + 1] = '0'; 110 | buffer[length + 2] = '\0'; 111 | length += 2; 112 | } 113 | 114 | /* Remove leading '+' from positive exponent. Also remove leading 115 | zeros from exponents (added by some printf() implementations) */ 116 | start = strchr(buffer, 'e'); 117 | if(start) { 118 | start++; 119 | end = start + 1; 120 | 121 | if(*start == '-') 122 | start++; 123 | 124 | while(*end == '0') 125 | end++; 126 | 127 | if(end != start) { 128 | memmove(start, end, length - (size_t)(end - buffer)); 129 | length -= (size_t)(end - start); 130 | } 131 | } 132 | 133 | return (int)length; 134 | } 135 | -------------------------------------------------------------------------------- /bitmain-readme.txt: -------------------------------------------------------------------------------- 1 | ###################################################################################### 2 | # # 3 | # BitMain setup and build instructions (on mingw32/Windows): # 4 | # # 5 | ###################################################################################### 6 | 7 | ************************************************************************************** 8 | * Build cgminer.exe * 9 | ************************************************************************************** 10 | Run the MinGW MSYS shell 11 | (Start Icon/keyboard key ==> All Programs ==> MinGW ==> MinGW Shell). 12 | Change the working directory to your CGMiner project folder. 13 | Example: cd cgminer-2.1.2 [Enter Key] if you are unsure then type "ls -la" 14 | Another way is to type "cd cg" and then press the tab key; It will auto fill. 15 | Type the lines below one at a time. Look for problems after each one before going on 16 | to the next. 17 | 18 | adl.sh (optional - see below) 19 | autoreconf -fvi 20 | CFLAGS="-O2 -msse2" ./configure (additional config options, see below) 21 | make 22 | strip cgminer.exe <== only do this if you are not compiling for debugging 23 | 24 | For bitmain mode: 25 | autoreconf -fvi 26 | CFLAGS="-O2 -msse2" ./configure --enable-bitmain --without-curses 27 | make 28 | 29 | ************************************************************************************** 30 | * Some ./configure options * 31 | ************************************************************************************** 32 | --enable-cpumining Build with cpu mining support(default disabled) 33 | --disable-opencl Override detection and disable building with opencl 34 | --disable-adl Override detection and disable building with adl 35 | --enable-bitforce Compile support for BitForce FPGAs(default disabled) 36 | --enable-icarus Compile support for Icarus Board(default disabled) 37 | --enable-bitmain Compile support for BitMain Devices(default disabled) 38 | --enable-modminer Compile support for ModMiner FPGAs(default disabled) 39 | --enable-ztex Compile support for Ztex Board(default disabled) 40 | --enable-scrypt Compile support for scrypt litecoin mining (default disabled) 41 | --without-curses Compile support for curses TUI (default enabled) 42 | --without-libudev Autodetect FPGAs using libudev (default enabled) 43 | 44 | ************************************************************************************** 45 | * Run cgminer for bitmain mode * 46 | ************************************************************************************** 47 | BitMain options: 48 | --bitmain-options baud:miner_count:asic_count:timeout:frequency 49 | 50 | For example: 51 | cgminer --bitmain-options 115200:24:10:30:300 -o http://stratum.btcguild.com:3333 -u xlc1985_1 -p abc123456 -D 52 | 53 | ###################################################################################### 54 | # # 55 | # BitMain setup and build instructions (on mingw32/Windows) complete # 56 | # # 57 | ###################################################################################### 58 | -------------------------------------------------------------------------------- /klist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 Andrew Smith - BlackArrow Ltd 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the Free 6 | * Software Foundation; either version 3 of the License, or (at your option) 7 | * any later version. See COPYING for more details. 8 | */ 9 | 10 | #ifndef KLIST_H 11 | #define KLIST_H 12 | 13 | #include 14 | 15 | #define KLIST_FFL " - from %s %s() line %d" 16 | #define KLIST_FFL_HERE __FILE__, __func__, __LINE__ 17 | #define KLIST_FFL_PASS file, func, line 18 | #define KLIST_FFL_ARGS __maybe_unused const char *file, \ 19 | __maybe_unused const char *func, \ 20 | __maybe_unused const int line 21 | 22 | typedef struct k_item { 23 | const char *name; 24 | struct k_item *prev; 25 | struct k_item *next; 26 | void *data; 27 | } K_ITEM; 28 | 29 | typedef struct k_list { 30 | const char *name; 31 | bool is_store; 32 | cglock_t *lock; 33 | struct k_item *head; 34 | struct k_item *tail; 35 | size_t siz; // item data size 36 | int total; // total allocated 37 | int count; // in this list 38 | int count_up; // incremented every time one is added 39 | int allocate; // number to intially allocate and each time we run out 40 | int limit; // total limit - 0 means unlimited 41 | bool do_tail; // track the tail? 42 | int item_mem_count; // how many item memory buffers have been allocated 43 | void **item_memory; // allocated item memory buffers 44 | int data_mem_count; // how many item data memory buffers have been allocated 45 | void **data_memory; // allocated item data memory buffers 46 | } K_LIST; 47 | 48 | /* 49 | * K_STORE is for a list of items taken from a K_LIST 50 | * The restriction is, a K_STORE must not allocate new items, 51 | * only the K_LIST should do that 52 | * i.e. all K_STORE items came from a K_LIST 53 | */ 54 | #define K_STORE K_LIST 55 | 56 | /* 57 | * N.B. all locking is done in the code calling the k_ functions 58 | */ 59 | #define K_WLOCK(_list) cg_wlock(_list->lock) 60 | #define K_WUNLOCK(_list) cg_wunlock(_list->lock) 61 | #define K_RLOCK(_list) cg_rlock(_list->lock) 62 | #define K_RUNLOCK(_list) cg_runlock(_list->lock) 63 | 64 | extern K_STORE *k_new_store(K_LIST *list); 65 | extern K_LIST *_k_new_list(const char *name, size_t siz, int allocate, int limit, bool do_tail, KLIST_FFL_ARGS); 66 | #define k_new_list(_name, _siz, _allocate, _limit, _do_tail) _k_new_list(_name, _siz, _allocate, _limit, _do_tail, KLIST_FFL_HERE) 67 | extern K_ITEM *_k_unlink_head(K_LIST *list, KLIST_FFL_ARGS); 68 | #define k_unlink_head(_list) _k_unlink_head(_list, KLIST_FFL_HERE) 69 | extern K_ITEM *_k_unlink_head_zero(K_LIST *list, KLIST_FFL_ARGS); 70 | #define k_unlink_head_zero(_list) _k_unlink_head_zero(_list, KLIST_FFL_HERE) 71 | extern K_ITEM *_k_unlink_tail(K_LIST *list, KLIST_FFL_ARGS); 72 | #define k_unlink_tail(_list) _k_unlink_tail(_list, KLIST_FFL_HERE) 73 | extern void _k_add_head(K_LIST *list, K_ITEM *item, KLIST_FFL_ARGS); 74 | #define k_add_head(_list, _item) _k_add_head(_list, _item, KLIST_FFL_HERE) 75 | // extern void k_free_head(K_LIST *list, K_ITEM *item, KLIST_FFL_ARGS); 76 | #define k_free_head(__list, __item) _k_add_head(__list, __item, KLIST_FFL_HERE) 77 | extern void _k_add_tail(K_LIST *list, K_ITEM *item, KLIST_FFL_ARGS); 78 | #define k_add_tail(_list, _item) _k_add_tail(_list, _item, KLIST_FFL_HERE) 79 | extern void k_unlink_item(K_LIST *list, K_ITEM *item); 80 | extern K_LIST *_k_free_list(K_LIST *list, KLIST_FFL_ARGS); 81 | #define k_free_list(_list) _k_free_list(_list, KLIST_FFL_HERE) 82 | extern K_STORE *_k_free_store(K_STORE *store, KLIST_FFL_ARGS); 83 | #define k_free_store(_store) _k_free_store(_store, KLIST_FFL_HERE) 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /ccan/opt/test/run-checkopt.c: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "utils.h" 9 | 10 | /* We don't actually want it to exit... */ 11 | static jmp_buf exited; 12 | #define errx save_and_jump 13 | 14 | static void save_and_jump(int ecode, const char *fmt, ...); 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | static char *output = NULL; 22 | 23 | static int saved_vprintf(const char *fmt, va_list ap) 24 | { 25 | char *p; 26 | int ret = vasprintf(&p, fmt, ap); 27 | 28 | if (output) { 29 | output = realloc(output, strlen(output) + strlen(p) + 1); 30 | strcat(output, p); 31 | free(p); 32 | } else 33 | output = p; 34 | return ret; 35 | } 36 | 37 | static void save_and_jump(int ecode, const char *fmt, ...) 38 | { 39 | va_list ap; 40 | 41 | va_start(ap, fmt); 42 | saved_vprintf(fmt, ap); 43 | va_end(ap); 44 | longjmp(exited, ecode + 1); 45 | } 46 | 47 | static void reset(void) 48 | { 49 | free(output); 50 | output = NULL; 51 | free(opt_table); 52 | opt_table = NULL; 53 | opt_count = opt_num_short = opt_num_short_arg = opt_num_long = 0; 54 | } 55 | 56 | int main(int argc, char *argv[]) 57 | { 58 | int exitval; 59 | 60 | plan_tests(14); 61 | 62 | exitval = setjmp(exited); 63 | if (exitval == 0) { 64 | /* Bad type. */ 65 | _opt_register("-a", OPT_SUBTABLE, (void *)opt_version_and_exit, 66 | NULL, NULL, "1.2.3", ""); 67 | fail("_opt_register returned?"); 68 | } else { 69 | ok1(exitval - 1 == 1); 70 | ok1(strstr(output, "Option -a: unknown entry type")); 71 | } 72 | reset(); 73 | 74 | exitval = setjmp(exited); 75 | if (exitval == 0) { 76 | /* NULL description. */ 77 | opt_register_noarg("-a", test_noarg, "", NULL); 78 | fail("_opt_register returned?"); 79 | } else { 80 | ok1(exitval - 1 == 1); 81 | ok1(strstr(output, "Option -a: description cannot be NULL")); 82 | } 83 | reset(); 84 | 85 | exitval = setjmp(exited); 86 | if (exitval == 0) { 87 | /* Bad option name. */ 88 | opt_register_noarg("a", test_noarg, "", ""); 89 | fail("_opt_register returned?"); 90 | } else { 91 | ok1(exitval - 1 == 1); 92 | ok1(strstr(output, "Option a: does not begin with '-'")); 93 | } 94 | 95 | reset(); 96 | 97 | exitval = setjmp(exited); 98 | if (exitval == 0) { 99 | /* Bad option name. */ 100 | opt_register_noarg("--", test_noarg, "", ""); 101 | fail("_opt_register returned?"); 102 | } else { 103 | ok1(exitval - 1 == 1); 104 | ok1(strstr(output, "Option --: invalid long option '--'")); 105 | } 106 | 107 | reset(); 108 | 109 | exitval = setjmp(exited); 110 | if (exitval == 0) { 111 | /* Bad option name. */ 112 | opt_register_noarg("--a|-aaa", test_noarg, "", ""); 113 | fail("_opt_register returned?"); 114 | } else { 115 | ok1(exitval - 1 == 1); 116 | ok1(strstr(output, 117 | "Option --a|-aaa: invalid short option '-aaa'")); 118 | } 119 | reset(); 120 | 121 | exitval = setjmp(exited); 122 | if (exitval == 0) { 123 | /* Documentation for non-optios. */ 124 | opt_register_noarg("--a foo", test_noarg, "", ""); 125 | fail("_opt_register returned?"); 126 | } else { 127 | ok1(exitval - 1 == 1); 128 | ok1(strstr(output, 129 | "Option --a foo: does not take arguments 'foo'")); 130 | } 131 | reset(); 132 | 133 | exitval = setjmp(exited); 134 | if (exitval == 0) { 135 | /* Documentation for non-optios. */ 136 | opt_register_noarg("--a=foo", test_noarg, "", ""); 137 | fail("_opt_register returned?"); 138 | } else { 139 | ok1(exitval - 1 == 1); 140 | ok1(strstr(output, 141 | "Option --a=foo: does not take arguments 'foo'")); 142 | } 143 | return exit_status(); 144 | } 145 | -------------------------------------------------------------------------------- /ccan/opt/parse.c: -------------------------------------------------------------------------------- 1 | /* Actual code to parse commandline. */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "private.h" 7 | 8 | /* glibc does this as: 9 | /tmp/opt-example: invalid option -- 'x' 10 | /tmp/opt-example: unrecognized option '--long' 11 | /tmp/opt-example: option '--someflag' doesn't allow an argument 12 | /tmp/opt-example: option '--s' is ambiguous 13 | /tmp/opt-example: option requires an argument -- 's' 14 | */ 15 | static int parse_err(void (*errlog)(const char *fmt, ...), 16 | const char *argv0, const char *arg, unsigned len, 17 | const char *problem) 18 | { 19 | errlog("%s: %.*s: %s", argv0, len, arg, problem); 20 | return -1; 21 | } 22 | 23 | static void consume_option(int *argc, char *argv[], unsigned optnum) 24 | { 25 | memmove(&argv[optnum], &argv[optnum+1], 26 | sizeof(argv[optnum]) * (*argc-optnum)); 27 | (*argc)--; 28 | } 29 | 30 | /* Returns 1 if argument consumed, 0 if all done, -1 on error. */ 31 | int parse_one(int *argc, char *argv[], unsigned *offset, 32 | void (*errlog)(const char *fmt, ...)) 33 | { 34 | unsigned i, arg, len; 35 | const char *o, *optarg = NULL; 36 | char *problem; 37 | 38 | if (getenv("POSIXLY_CORRECT")) { 39 | /* Don't find options after non-options. */ 40 | arg = 1; 41 | } else { 42 | for (arg = 1; argv[arg]; arg++) { 43 | if (argv[arg][0] == '-') 44 | break; 45 | } 46 | } 47 | 48 | if (!argv[arg] || argv[arg][0] != '-') 49 | return 0; 50 | 51 | /* Special arg terminator option. */ 52 | if (strcmp(argv[arg], "--") == 0) { 53 | consume_option(argc, argv, arg); 54 | return 0; 55 | } 56 | 57 | /* Long options start with -- */ 58 | if (argv[arg][1] == '-') { 59 | assert(*offset == 0); 60 | for (o = first_lopt(&i, &len); o; o = next_lopt(o, &i, &len)) { 61 | if (strncmp(argv[arg] + 2, o, len) != 0) 62 | continue; 63 | if (argv[arg][2 + len] == '=') 64 | optarg = argv[arg] + 2 + len + 1; 65 | else if (argv[arg][2 + len] != '\0') 66 | continue; 67 | break; 68 | } 69 | if (!o) 70 | return parse_err(errlog, argv[0], 71 | argv[arg], strlen(argv[arg]), 72 | "unrecognized option"); 73 | /* For error messages, we include the leading '--' */ 74 | o -= 2; 75 | len += 2; 76 | } else { 77 | /* offset allows us to handle -abc */ 78 | for (o = first_sopt(&i); o; o = next_sopt(o, &i)) { 79 | if (argv[arg][*offset + 1] != *o) 80 | continue; 81 | (*offset)++; 82 | break; 83 | } 84 | if (!o) 85 | return parse_err(errlog, argv[0], 86 | argv[arg], strlen(argv[arg]), 87 | "unrecognized option"); 88 | /* For error messages, we include the leading '-' */ 89 | o--; 90 | len = 2; 91 | } 92 | 93 | if (opt_table[i].type == OPT_NOARG) { 94 | if (optarg) 95 | return parse_err(errlog, argv[0], o, len, 96 | "doesn't allow an argument"); 97 | problem = opt_table[i].cb(opt_table[i].u.arg); 98 | } else { 99 | if (!optarg) { 100 | /* Swallow any short options as optarg, eg -afile */ 101 | if (*offset && argv[arg][*offset + 1]) { 102 | optarg = argv[arg] + *offset + 1; 103 | *offset = 0; 104 | } else 105 | optarg = argv[arg+1]; 106 | } 107 | if (!optarg) 108 | return parse_err(errlog, argv[0], o, len, 109 | "requires an argument"); 110 | problem = opt_table[i].cb_arg(optarg, opt_table[i].u.arg); 111 | } 112 | 113 | if (problem) { 114 | parse_err(errlog, argv[0], o, len, problem); 115 | free(problem); 116 | return -1; 117 | } 118 | 119 | /* If no more letters in that short opt, reset offset. */ 120 | if (*offset && !argv[arg][*offset + 1]) 121 | *offset = 0; 122 | 123 | /* All finished with that option? */ 124 | if (*offset == 0) { 125 | consume_option(argc, argv, arg); 126 | if (optarg && optarg == argv[arg]) 127 | consume_option(argc, argv, arg); 128 | } 129 | return 1; 130 | } 131 | -------------------------------------------------------------------------------- /bench_block.h: -------------------------------------------------------------------------------- 1 | #if !defined(__BENCH_BLOCK_H__) 2 | #define __BENCH_BLOCK_H__ 1 3 | 4 | // Random work pulled from a pool 5 | #define CGMINER_BENCHMARK_BLOCK \ 6 | 0x00, 0x00, 0x00, 0x01, 0x20, 0x00, 0xD8, 0x07, 0x17, 0xC9, 0x13, 0x6F, 0xDC, 0xBE, 0xDE, 0xB7, \ 7 | 0xB2, 0x14, 0xEF, 0xD1, 0x72, 0x7F, 0xA3, 0x72, 0xB2, 0x5D, 0x88, 0xF0, 0x00, 0x00, 0x05, 0xAA, \ 8 | 0x00, 0x00, 0x00, 0x00, 0x92, 0x8B, 0x4C, 0x77, 0xF5, 0xB2, 0xE6, 0x56, 0x96, 0x27, 0xE0, 0x66, \ 9 | 0x3C, 0x5B, 0xDD, 0xDC, 0x88, 0x6A, 0x7D, 0x7C, 0x7B, 0x8C, 0xE4, 0x92, 0x38, 0x92, 0x58, 0x2E, \ 10 | 0x18, 0x4D, 0x95, 0x9E, 0x4E, 0x44, 0xF1, 0x5F, 0x1A, 0x08, 0xE1, 0xE5, 0x00, 0x00, 0x00, 0x00, \ 11 | 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 12 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 13 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, \ 14 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 15 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 16 | 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 17 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, \ 18 | 0x86, 0x7E, 0x3A, 0xAF, 0x37, 0x83, 0xAF, 0xA0, 0xB5, 0x33, 0x2C, 0x28, 0xED, 0xA9, 0x89, 0x3E, \ 19 | 0x0A, 0xB6, 0x46, 0x81, 0xC2, 0x71, 0x4F, 0x34, 0x5A, 0x74, 0x89, 0x0E, 0x2B, 0x04, 0xB3, 0x16, \ 20 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \ 21 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, \ 22 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 23 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 24 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 25 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 26 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 27 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 28 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 29 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 30 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 31 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 32 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 33 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 34 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 35 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0xF6, 0x09, 0x02, 0x00, 0x00, 0x00, 0x00, \ 36 | 0x55, 0xF1, 0x44, 0x4E, 0x00, 0x00, 0x00, 0x00, 0x79, 0x63, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, \ 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 38 | 39 | #endif // !defined(__BENCH_BLOCK_H__) 40 | -------------------------------------------------------------------------------- /API.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) Andrew Smith 2012-2013 4 | * 5 | * Usage: java API command ip port 6 | * 7 | * If any are missing or blank they use the defaults: 8 | * 9 | * command = 'summary' 10 | * ip = '127.0.0.1' 11 | * port = '4028' 12 | * 13 | */ 14 | 15 | import java.net.*; 16 | import java.io.*; 17 | 18 | class API 19 | { 20 | static private final int MAXRECEIVESIZE = 65535; 21 | 22 | static private Socket socket = null; 23 | 24 | private void closeAll() throws Exception 25 | { 26 | if (socket != null) 27 | { 28 | socket.close(); 29 | socket = null; 30 | } 31 | } 32 | 33 | public void display(String result) throws Exception 34 | { 35 | String value; 36 | String name; 37 | String[] sections = result.split("\\|", 0); 38 | 39 | for (int i = 0; i < sections.length; i++) 40 | { 41 | if (sections[i].trim().length() > 0) 42 | { 43 | String[] data = sections[i].split(",", 0); 44 | 45 | for (int j = 0; j < data.length; j++) 46 | { 47 | String[] nameval = data[j].split("=", 2); 48 | 49 | if (j == 0) 50 | { 51 | if (nameval.length > 1 52 | && Character.isDigit(nameval[1].charAt(0))) 53 | name = nameval[0] + nameval[1]; 54 | else 55 | name = nameval[0]; 56 | 57 | System.out.println("[" + name + "] =>"); 58 | System.out.println("("); 59 | } 60 | 61 | if (nameval.length > 1) 62 | { 63 | name = nameval[0]; 64 | value = nameval[1]; 65 | } 66 | else 67 | { 68 | name = "" + j; 69 | value = nameval[0]; 70 | } 71 | 72 | System.out.println(" ["+name+"] => "+value); 73 | } 74 | System.out.println(")"); 75 | } 76 | } 77 | } 78 | 79 | public void process(String cmd, InetAddress ip, int port) throws Exception 80 | { 81 | StringBuffer sb = new StringBuffer(); 82 | char buf[] = new char[MAXRECEIVESIZE]; 83 | int len = 0; 84 | 85 | System.out.println("Attempting to send '"+cmd+"' to "+ip.getHostAddress()+":"+port); 86 | 87 | try 88 | { 89 | socket = new Socket(ip, port); 90 | PrintStream ps = new PrintStream(socket.getOutputStream()); 91 | ps.print(cmd.toLowerCase().toCharArray()); 92 | ps.flush(); 93 | 94 | InputStreamReader isr = new InputStreamReader(socket.getInputStream()); 95 | while (0x80085 > 0) 96 | { 97 | len = isr.read(buf, 0, MAXRECEIVESIZE); 98 | if (len < 1) 99 | break; 100 | sb.append(buf, 0, len); 101 | if (buf[len-1] == '\0') 102 | break; 103 | } 104 | 105 | closeAll(); 106 | } 107 | catch (IOException ioe) 108 | { 109 | System.err.println(ioe.toString()); 110 | closeAll(); 111 | return; 112 | } 113 | 114 | String result = sb.toString(); 115 | 116 | System.out.println("Answer='"+result+"'"); 117 | 118 | display(result); 119 | } 120 | 121 | public API(String command, String _ip, String _port) throws Exception 122 | { 123 | InetAddress ip; 124 | int port; 125 | 126 | try 127 | { 128 | ip = InetAddress.getByName(_ip); 129 | } 130 | catch (UnknownHostException uhe) 131 | { 132 | System.err.println("Unknown host " + _ip + ": " + uhe); 133 | return; 134 | } 135 | 136 | try 137 | { 138 | port = Integer.parseInt(_port); 139 | } 140 | catch (NumberFormatException nfe) 141 | { 142 | System.err.println("Invalid port " + _port + ": " + nfe); 143 | return; 144 | } 145 | 146 | process(command, ip, port); 147 | } 148 | 149 | public static void main(String[] params) throws Exception 150 | { 151 | String command = "summary"; 152 | String ip = "127.0.0.1"; 153 | String port = "4028"; 154 | 155 | if (params.length > 0 && params[0].trim().length() > 0) 156 | command = params[0].trim(); 157 | 158 | if (params.length > 1 && params[1].trim().length() > 0) 159 | ip = params[1].trim(); 160 | 161 | if (params.length > 2 && params[2].trim().length() > 0) 162 | port = params[2].trim(); 163 | 164 | new API(command, ip, port); 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /compat/libusb-1.0/PORTING: -------------------------------------------------------------------------------- 1 | PORTING LIBUSB TO OTHER PLATFORMS 2 | 3 | Introduction 4 | ============ 5 | 6 | This document is aimed at developers wishing to port libusb to unsupported 7 | platforms. I believe the libusb API is OS-independent, so by supporting 8 | multiple operating systems we pave the way for cross-platform USB device 9 | drivers. 10 | 11 | Implementation-wise, the basic idea is that you provide an interface to 12 | libusb's internal "backend" API, which performs the appropriate operations on 13 | your target platform. 14 | 15 | In terms of USB I/O, your backend provides functionality to submit 16 | asynchronous transfers (synchronous transfers are implemented in the higher 17 | layers, based on the async interface). Your backend must also provide 18 | functionality to cancel those transfers. 19 | 20 | Your backend must also provide an event handling function to "reap" ongoing 21 | transfers and process their results. 22 | 23 | The backend must also provide standard functions for other USB operations, 24 | e.g. setting configuration, obtaining descriptors, etc. 25 | 26 | 27 | File descriptors for I/O polling 28 | ================================ 29 | 30 | For libusb to work, your event handling function obviously needs to be called 31 | at various points in time. Your backend must provide a set of file descriptors 32 | which libusb and its users can pass to poll() or select() to determine when 33 | it is time to call the event handling function. 34 | 35 | On Linux, this is easy: the usbfs kernel interface exposes a file descriptor 36 | which can be passed to poll(). If something similar is not true for your 37 | platform, you can emulate this using an internal library thread to reap I/O as 38 | necessary, and a pipe() with the main library to raise events. The file 39 | descriptor of the pipe can then be provided to libusb as an event source. 40 | 41 | 42 | Interface semantics and documentation 43 | ===================================== 44 | 45 | Documentation of the backend interface can be found in libusbi.h inside the 46 | usbi_os_backend structure definition. 47 | 48 | Your implementations of these functions will need to call various internal 49 | libusb functions, prefixed with "usbi_". Documentation for these functions 50 | can be found in the .c files where they are implemented. 51 | 52 | You probably want to skim over *all* the documentation before starting your 53 | implementation. For example, you probably need to allocate and store private 54 | OS-specific data for device handles, but the documentation for the mechanism 55 | for doing so is probably not the first thing you will see. 56 | 57 | The Linux backend acts as a good example - view it as a reference 58 | implementation which you should try to match the behaviour of. 59 | 60 | 61 | Getting started 62 | =============== 63 | 64 | 1. Modify configure.ac to detect your platform appropriately (see the OS_LINUX 65 | stuff for an example). 66 | 67 | 2. Implement your backend in the libusb/os/ directory, modifying 68 | libusb/os/Makefile.am appropriately. 69 | 70 | 3. Add preprocessor logic to the top of libusb/core.c to statically assign the 71 | right usbi_backend for your platform. 72 | 73 | 4. Produce and test your implementation. 74 | 75 | 5. Send your implementation to libusb-devel mailing list. 76 | 77 | 78 | Implementation difficulties? Questions? 79 | ======================================= 80 | 81 | If you encounter difficulties porting libusb to your platform, please raise 82 | these issues on the libusb-devel mailing list. Where possible and sensible, I 83 | am interested in solving problems preventing libusb from operating on other 84 | platforms. 85 | 86 | The libusb-devel mailing list is also a good place to ask questions and 87 | make suggestions about the internal API. Hopefully we can produce some 88 | better documentation based on your questions and other input. 89 | 90 | You are encouraged to get involved in the process; if the library needs 91 | some infrastructure additions/modifications to better support your platform, 92 | you are encouraged to make such changes (in cleanly distinct patch 93 | submissions). Even if you do not make such changes yourself, please do raise 94 | the issues on the mailing list at the very minimum. 95 | 96 | -------------------------------------------------------------------------------- /ccan/opt/test/run-usage.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "utils.h" 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | static char *my_cb(void *p) 13 | { 14 | return NULL; 15 | } 16 | 17 | static void reset_options(void) 18 | { 19 | free(opt_table); 20 | opt_table = NULL; 21 | opt_count = opt_num_short = opt_num_short_arg = opt_num_long = 0; 22 | } 23 | 24 | /* Test helpers. */ 25 | int main(int argc, char *argv[]) 26 | { 27 | char *output; 28 | char *longname = strdup("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); 29 | char *shortname = strdup("shortname"); 30 | 31 | plan_tests(48); 32 | opt_register_table(subtables, NULL); 33 | opt_register_noarg("--kkk|-k", my_cb, NULL, "magic kkk option"); 34 | opt_register_noarg("-?", opt_usage_and_exit, "...", 35 | "This message"); 36 | opt_register_arg("--longname", opt_set_charp, opt_show_charp, 37 | &longname, "a really long option default"); 38 | opt_register_arg("--shortname", opt_set_charp, opt_show_charp, 39 | &shortname, "a short option default"); 40 | output = opt_usage("my name", "ExTrA Args"); 41 | diag("%s", output); 42 | ok1(strstr(output, "Usage: my name")); 43 | ok1(strstr(output, "--jjj|-j|--lll|-l ")); 44 | ok1(strstr(output, "ExTrA Args")); 45 | ok1(strstr(output, "-a ")); 46 | ok1(strstr(output, " Description of a\n")); 47 | ok1(strstr(output, "-b ")); 48 | ok1(strstr(output, " Description of b (default: b)\n")); 49 | ok1(strstr(output, "--ddd ")); 50 | ok1(strstr(output, " Description of ddd\n")); 51 | ok1(strstr(output, "--eee ")); 52 | ok1(strstr(output, " (default: eee)\n")); 53 | ok1(strstr(output, "long table options:\n")); 54 | ok1(strstr(output, "--ggg|-g ")); 55 | ok1(strstr(output, " Description of ggg\n")); 56 | ok1(strstr(output, "-h|--hhh ")); 57 | ok1(strstr(output, " Description of hhh\n")); 58 | ok1(strstr(output, "--kkk|-k")); 59 | ok1(strstr(output, "magic kkk option")); 60 | /* This entry is hidden. */ 61 | ok1(!strstr(output, "--mmm|-m")); 62 | free(output); 63 | 64 | /* NULL should use string from registered options. */ 65 | output = opt_usage("my name", NULL); 66 | diag("%s", output); 67 | ok1(strstr(output, "Usage: my name")); 68 | ok1(strstr(output, "--jjj|-j|--lll|-l ")); 69 | ok1(strstr(output, "...")); 70 | ok1(strstr(output, "-a ")); 71 | ok1(strstr(output, " Description of a\n")); 72 | ok1(strstr(output, "-b ")); 73 | ok1(strstr(output, " Description of b (default: b)\n")); 74 | ok1(strstr(output, "--ddd ")); 75 | ok1(strstr(output, " Description of ddd\n")); 76 | ok1(strstr(output, "--eee ")); 77 | ok1(strstr(output, " (default: eee)\n")); 78 | ok1(strstr(output, "long table options:\n")); 79 | ok1(strstr(output, "--ggg|-g ")); 80 | ok1(strstr(output, " Description of ggg\n")); 81 | ok1(strstr(output, "-h|--hhh ")); 82 | ok1(strstr(output, " Description of hhh\n")); 83 | ok1(strstr(output, "--kkk|-k")); 84 | ok1(strstr(output, "magic kkk option")); 85 | ok1(strstr(output, "--longname")); 86 | ok1(strstr(output, "a really long option default")); 87 | ok1(strstr(output, "(default: \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"...)")); 88 | ok1(strstr(output, "--shortname")); 89 | ok1(strstr(output, "a short option default")); 90 | ok1(strstr(output, "(default: \"shortname\")")); 91 | /* This entry is hidden. */ 92 | ok1(!strstr(output, "--mmm|-m")); 93 | free(output); 94 | 95 | reset_options(); 96 | /* Empty table test. */ 97 | output = opt_usage("nothing", NULL); 98 | ok1(strstr(output, "Usage: nothing \n")); 99 | free(output); 100 | 101 | /* No short args. */ 102 | opt_register_noarg("--aaa", test_noarg, NULL, "AAAAll"); 103 | output = opt_usage("onearg", NULL); 104 | ok1(strstr(output, "Usage: onearg \n")); 105 | ok1(strstr(output, "--aaa")); 106 | ok1(strstr(output, "AAAAll")); 107 | free(output); 108 | 109 | free(shortname); 110 | free(longname); 111 | return exit_status(); 112 | } 113 | -------------------------------------------------------------------------------- /m4/onceonly.m4: -------------------------------------------------------------------------------- 1 | # onceonly.m4 serial 7 2 | dnl Copyright (C) 2002-2003, 2005-2006, 2008-2011 Free Software Foundation, 3 | dnl Inc. 4 | dnl This file is free software, distributed under the terms of the GNU 5 | dnl General Public License. As a special exception to the GNU General 6 | dnl Public License, this file may be distributed as part of a program 7 | dnl that contains a configuration script generated by Autoconf, under 8 | dnl the same distribution terms as the rest of that program. 9 | 10 | dnl This file defines some "once only" variants of standard autoconf macros. 11 | dnl AC_CHECK_HEADERS_ONCE like AC_CHECK_HEADERS 12 | dnl AC_CHECK_FUNCS_ONCE like AC_CHECK_FUNCS 13 | dnl AC_CHECK_DECLS_ONCE like AC_CHECK_DECLS 14 | dnl AC_REQUIRE([AC_FUNC_STRCOLL]) like AC_FUNC_STRCOLL 15 | dnl The advantage is that the check for each of the headers/functions/decls 16 | dnl will be put only once into the 'configure' file. It keeps the size of 17 | dnl the 'configure' file down, and avoids redundant output when 'configure' 18 | dnl is run. 19 | dnl The drawback is that the checks cannot be conditionalized. If you write 20 | dnl if some_condition; then gl_CHECK_HEADERS(stdlib.h); fi 21 | dnl inside an AC_DEFUNed function, the gl_CHECK_HEADERS macro call expands to 22 | dnl empty, and the check will be inserted before the body of the AC_DEFUNed 23 | dnl function. 24 | 25 | dnl The original code implemented AC_CHECK_HEADERS_ONCE and AC_CHECK_FUNCS_ONCE 26 | dnl in terms of AC_DEFUN and AC_REQUIRE. This implementation uses diversions to 27 | dnl named sections DEFAULTS and INIT_PREPARE in order to check all requested 28 | dnl headers at once, thus reducing the size of 'configure'. It is known to work 29 | dnl with autoconf 2.57..2.62 at least . The size reduction is ca. 9%. 30 | 31 | dnl Autoconf version 2.59 plus gnulib is required; this file is not needed 32 | dnl with Autoconf 2.60 or greater. But note that autoconf's implementation of 33 | dnl AC_CHECK_DECLS_ONCE expects a comma-separated list of symbols as first 34 | dnl argument! 35 | AC_PREREQ([2.59]) 36 | 37 | # AC_CHECK_HEADERS_ONCE(HEADER1 HEADER2 ...) is a once-only variant of 38 | # AC_CHECK_HEADERS(HEADER1 HEADER2 ...). 39 | AC_DEFUN([AC_CHECK_HEADERS_ONCE], [ 40 | : 41 | m4_foreach_w([gl_HEADER_NAME], [$1], [ 42 | AC_DEFUN([gl_CHECK_HEADER_]m4_quote(m4_translit(gl_HEADER_NAME, 43 | [./-], [___])), [ 44 | m4_divert_text([INIT_PREPARE], 45 | [gl_header_list="$gl_header_list gl_HEADER_NAME"]) 46 | gl_HEADERS_EXPANSION 47 | AH_TEMPLATE(AS_TR_CPP([HAVE_]m4_defn([gl_HEADER_NAME])), 48 | [Define to 1 if you have the <]m4_defn([gl_HEADER_NAME])[> header file.]) 49 | ]) 50 | AC_REQUIRE([gl_CHECK_HEADER_]m4_quote(m4_translit(gl_HEADER_NAME, 51 | [./-], [___]))) 52 | ]) 53 | ]) 54 | m4_define([gl_HEADERS_EXPANSION], [ 55 | m4_divert_text([DEFAULTS], [gl_header_list=]) 56 | AC_CHECK_HEADERS([$gl_header_list]) 57 | m4_define([gl_HEADERS_EXPANSION], []) 58 | ]) 59 | 60 | # AC_CHECK_FUNCS_ONCE(FUNC1 FUNC2 ...) is a once-only variant of 61 | # AC_CHECK_FUNCS(FUNC1 FUNC2 ...). 62 | AC_DEFUN([AC_CHECK_FUNCS_ONCE], [ 63 | : 64 | m4_foreach_w([gl_FUNC_NAME], [$1], [ 65 | AC_DEFUN([gl_CHECK_FUNC_]m4_defn([gl_FUNC_NAME]), [ 66 | m4_divert_text([INIT_PREPARE], 67 | [gl_func_list="$gl_func_list gl_FUNC_NAME"]) 68 | gl_FUNCS_EXPANSION 69 | AH_TEMPLATE(AS_TR_CPP([HAVE_]m4_defn([gl_FUNC_NAME])), 70 | [Define to 1 if you have the `]m4_defn([gl_FUNC_NAME])[' function.]) 71 | ]) 72 | AC_REQUIRE([gl_CHECK_FUNC_]m4_defn([gl_FUNC_NAME])) 73 | ]) 74 | ]) 75 | m4_define([gl_FUNCS_EXPANSION], [ 76 | m4_divert_text([DEFAULTS], [gl_func_list=]) 77 | AC_CHECK_FUNCS([$gl_func_list]) 78 | m4_define([gl_FUNCS_EXPANSION], []) 79 | ]) 80 | 81 | # AC_CHECK_DECLS_ONCE(DECL1 DECL2 ...) is a once-only variant of 82 | # AC_CHECK_DECLS(DECL1, DECL2, ...). 83 | AC_DEFUN([AC_CHECK_DECLS_ONCE], [ 84 | : 85 | m4_foreach_w([gl_DECL_NAME], [$1], [ 86 | AC_DEFUN([gl_CHECK_DECL_]m4_defn([gl_DECL_NAME]), [ 87 | AC_CHECK_DECLS(m4_defn([gl_DECL_NAME])) 88 | ]) 89 | AC_REQUIRE([gl_CHECK_DECL_]m4_defn([gl_DECL_NAME])) 90 | ]) 91 | ]) 92 | -------------------------------------------------------------------------------- /compat/libusb-1.0/libusb/os/poll_windows.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Windows compat: POSIX compatibility wrapper 3 | * Copyright (C) 2009-2010 Pete Batard 4 | * With contributions from Michael Plante, Orin Eman et al. 5 | * Parts of poll implementation from libusb-win32, by Stephan Meyer et al. 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | * 21 | */ 22 | #pragma once 23 | 24 | #include 25 | 26 | #if defined(_MSC_VER) 27 | // disable /W4 MSVC warnings that are benign 28 | #pragma warning(disable:4127) // conditional expression is constant 29 | #endif 30 | 31 | // Handle synchronous completion through the overlapped structure 32 | #if !defined(STATUS_REPARSE) // reuse the REPARSE status code 33 | #define STATUS_REPARSE ((LONG)0x00000104L) 34 | #endif 35 | #define STATUS_COMPLETED_SYNCHRONOUSLY STATUS_REPARSE 36 | #define HasOverlappedIoCompletedSync(lpOverlapped) (((DWORD)(lpOverlapped)->Internal) == STATUS_COMPLETED_SYNCHRONOUSLY) 37 | 38 | #define DUMMY_HANDLE ((HANDLE)(LONG_PTR)-2) 39 | 40 | enum windows_version { 41 | WINDOWS_UNSUPPORTED, 42 | WINDOWS_XP, 43 | WINDOWS_2003, // also includes XP 64 44 | WINDOWS_VISTA_AND_LATER, 45 | }; 46 | extern enum windows_version windows_version; 47 | 48 | #define MAX_FDS 256 49 | 50 | #define POLLIN 0x0001 /* There is data to read */ 51 | #define POLLPRI 0x0002 /* There is urgent data to read */ 52 | #define POLLOUT 0x0004 /* Writing now will not block */ 53 | #define POLLERR 0x0008 /* Error condition */ 54 | #define POLLHUP 0x0010 /* Hung up */ 55 | #define POLLNVAL 0x0020 /* Invalid request: fd not open */ 56 | 57 | struct pollfd { 58 | int fd; /* file descriptor */ 59 | short events; /* requested events */ 60 | short revents; /* returned events */ 61 | }; 62 | 63 | // access modes 64 | enum rw_type { 65 | RW_NONE, 66 | RW_READ, 67 | RW_WRITE, 68 | }; 69 | 70 | // fd struct that can be used for polling on Windows 71 | struct winfd { 72 | int fd; // what's exposed to libusb core 73 | HANDLE handle; // what we need to attach overlapped to the I/O op, so we can poll it 74 | OVERLAPPED* overlapped; // what will report our I/O status 75 | enum rw_type rw; // I/O transfer direction: read *XOR* write (NOT BOTH) 76 | }; 77 | extern const struct winfd INVALID_WINFD; 78 | 79 | int usbi_pipe(int pipefd[2]); 80 | int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout); 81 | ssize_t usbi_write(int fd, const void *buf, size_t count); 82 | ssize_t usbi_read(int fd, void *buf, size_t count); 83 | int usbi_close(int fd); 84 | 85 | void init_polling(void); 86 | void exit_polling(void); 87 | struct winfd usbi_create_fd(HANDLE handle, int access_mode); 88 | void usbi_free_fd(int fd); 89 | struct winfd fd_to_winfd(int fd); 90 | struct winfd handle_to_winfd(HANDLE handle); 91 | struct winfd overlapped_to_winfd(OVERLAPPED* overlapped); 92 | 93 | /* 94 | * Timeval operations 95 | */ 96 | #if defined(DDKBUILD) 97 | #include // defines timeval functions on DDK 98 | #endif 99 | 100 | #if !defined(TIMESPEC_TO_TIMEVAL) 101 | #define TIMESPEC_TO_TIMEVAL(tv, ts) { \ 102 | (tv)->tv_sec = (long)(ts)->tv_sec; \ 103 | (tv)->tv_usec = (long)(ts)->tv_nsec / 1000; \ 104 | } 105 | #endif 106 | #if !defined(timersub) 107 | #define timersub(a, b, result) \ 108 | do { \ 109 | (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ 110 | (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ 111 | if ((result)->tv_usec < 0) { \ 112 | --(result)->tv_sec; \ 113 | (result)->tv_usec += 1000000; \ 114 | } \ 115 | } while (0) 116 | #endif 117 | 118 | -------------------------------------------------------------------------------- /ccan/opt/helpers.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "private.h" 7 | 8 | /* Upper bound to sprintf this simple type? Each 3 bits < 1 digit. */ 9 | #define CHAR_SIZE(type) (((sizeof(type)*CHAR_BIT + 2) / 3) + 1) 10 | 11 | /* FIXME: asprintf module? */ 12 | static char *arg_bad(const char *fmt, const char *arg) 13 | { 14 | char *str = malloc(strlen(fmt) + strlen(arg)); 15 | sprintf(str, fmt, arg); 16 | return str; 17 | } 18 | 19 | char *opt_set_bool(bool *b) 20 | { 21 | *b = true; 22 | return NULL; 23 | } 24 | 25 | char *opt_set_invbool(bool *b) 26 | { 27 | *b = false; 28 | return NULL; 29 | } 30 | 31 | char *opt_set_bool_arg(const char *arg, bool *b) 32 | { 33 | if (!strcasecmp(arg, "yes") || !strcasecmp(arg, "true")) 34 | return opt_set_bool(b); 35 | if (!strcasecmp(arg, "no") || !strcasecmp(arg, "false")) 36 | return opt_set_invbool(b); 37 | 38 | return opt_invalid_argument(arg); 39 | } 40 | 41 | char *opt_set_invbool_arg(const char *arg, bool *b) 42 | { 43 | char *err = opt_set_bool_arg(arg, b); 44 | 45 | if (!err) 46 | *b = !*b; 47 | return err; 48 | } 49 | 50 | /* Set a char *. */ 51 | char *opt_set_charp(const char *arg, char **p) 52 | { 53 | *p = (char *)arg; 54 | return NULL; 55 | } 56 | 57 | /* Set an integer value, various forms. Sets to 1 on arg == NULL. */ 58 | char *opt_set_intval(const char *arg, int *i) 59 | { 60 | long l; 61 | char *err = opt_set_longval(arg, &l); 62 | 63 | if (err) 64 | return err; 65 | *i = l; 66 | /* Beware truncation... */ 67 | if (*i != l) 68 | return arg_bad("value '%s' does not fit into an integer", arg); 69 | return err; 70 | } 71 | 72 | char *opt_set_floatval(const char *arg, float *f) 73 | { 74 | char *endp; 75 | 76 | errno = 0; 77 | *f = strtof(arg, &endp); 78 | if (*endp || !arg[0]) 79 | return arg_bad("'%s' is not a number", arg); 80 | if (errno) 81 | return arg_bad("'%s' is out of range", arg); 82 | return NULL; 83 | } 84 | 85 | char *opt_set_uintval(const char *arg, unsigned int *ui) 86 | { 87 | int i; 88 | char *err = opt_set_intval(arg, &i); 89 | 90 | if (err) 91 | return err; 92 | if (i < 0) 93 | return arg_bad("'%s' is negative", arg); 94 | *ui = i; 95 | return NULL; 96 | } 97 | 98 | char *opt_set_longval(const char *arg, long *l) 99 | { 100 | char *endp; 101 | 102 | /* This is how the manpage says to do it. Yech. */ 103 | errno = 0; 104 | *l = strtol(arg, &endp, 0); 105 | if (*endp || !arg[0]) 106 | return arg_bad("'%s' is not a number", arg); 107 | if (errno) 108 | return arg_bad("'%s' is out of range", arg); 109 | return NULL; 110 | } 111 | 112 | char *opt_set_ulongval(const char *arg, unsigned long *ul) 113 | { 114 | long int l; 115 | char *err; 116 | 117 | err = opt_set_longval(arg, &l); 118 | if (err) 119 | return err; 120 | *ul = l; 121 | if (l < 0) 122 | return arg_bad("'%s' is negative", arg); 123 | return NULL; 124 | } 125 | 126 | char *opt_inc_intval(int *i) 127 | { 128 | (*i)++; 129 | return NULL; 130 | } 131 | 132 | /* Display version string. */ 133 | char *opt_version_and_exit(const char *version) 134 | { 135 | printf("%s\n", version); 136 | fflush(stdout); 137 | exit(0); 138 | } 139 | 140 | char *opt_usage_and_exit(const char *extra) 141 | { 142 | printf("%s", opt_usage(opt_argv0, extra)); 143 | fflush(stdout); 144 | exit(0); 145 | } 146 | 147 | void opt_show_bool(char buf[OPT_SHOW_LEN], const bool *b) 148 | { 149 | strncpy(buf, *b ? "true" : "false", OPT_SHOW_LEN); 150 | } 151 | 152 | void opt_show_invbool(char buf[OPT_SHOW_LEN], const bool *b) 153 | { 154 | strncpy(buf, *b ? "false" : "true", OPT_SHOW_LEN); 155 | } 156 | 157 | void opt_show_charp(char buf[OPT_SHOW_LEN], char *const *p) 158 | { 159 | size_t len = strlen(*p); 160 | buf[0] = '"'; 161 | if (len > OPT_SHOW_LEN - 2) 162 | len = OPT_SHOW_LEN - 2; 163 | strncpy(buf+1, *p, len); 164 | buf[1+len] = '"'; 165 | if (len < OPT_SHOW_LEN - 2) 166 | buf[2+len] = '\0'; 167 | } 168 | 169 | /* Set an integer value, various forms. Sets to 1 on arg == NULL. */ 170 | void opt_show_intval(char buf[OPT_SHOW_LEN], const int *i) 171 | { 172 | snprintf(buf, OPT_SHOW_LEN, "%i", *i); 173 | } 174 | 175 | void opt_show_floatval(char buf[OPT_SHOW_LEN], const float *f) 176 | { 177 | snprintf(buf, OPT_SHOW_LEN, "%.1f", *f); 178 | } 179 | 180 | void opt_show_uintval(char buf[OPT_SHOW_LEN], const unsigned int *ui) 181 | { 182 | snprintf(buf, OPT_SHOW_LEN, "%u", *ui); 183 | } 184 | 185 | void opt_show_longval(char buf[OPT_SHOW_LEN], const long *l) 186 | { 187 | snprintf(buf, OPT_SHOW_LEN, "%li", *l); 188 | } 189 | 190 | void opt_show_ulongval(char buf[OPT_SHOW_LEN], const unsigned long *ul) 191 | { 192 | snprintf(buf, OPT_SHOW_LEN, "%lu", *ul); 193 | } 194 | -------------------------------------------------------------------------------- /bitforce-firmware-flash.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Luke Dashjr 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the Free 6 | * Software Foundation; either version 3 of the License, or (at your option) 7 | * any later version. See COPYING for more details. 8 | */ 9 | 10 | #define _BSD_SOURCE 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | #define BFL_FILE_MAGIC "BFLDATA" 19 | #define BFL_UPLOAD_MAGIC "NGH-STREAM" 20 | 21 | #define myassert(expr, n, ...) \ 22 | do { \ 23 | if (!(expr)) { \ 24 | fprintf(stderr, __VA_ARGS__); \ 25 | return n; \ 26 | } \ 27 | } while(0) 28 | 29 | #define ERRRESP(buf) buf, (buf[strlen(buf)-1] == '\n' ? "" : "\n") 30 | 31 | #define WAITFOROK(n, msg) \ 32 | do { \ 33 | myassert(fgets(buf, sizeof(buf), BFL), n, "Error reading response from " msg "\n"); \ 34 | myassert(!strcmp(buf, "OK\n"), n, "Invalid response from " msg ": %s%s", ERRRESP(buf)); \ 35 | } while(0) 36 | 37 | int main(int argc, char**argv) 38 | { 39 | myassert(argc == 3, 1, "Usage: %s \n", argv[0]); 40 | setbuf(stdout, NULL); 41 | 42 | // Check filename 43 | char *FWname = basename(strdup(argv[2])); 44 | size_t FWnameLen = strlen(FWname); 45 | myassert(FWnameLen <= 255, 0x0f, "Firmware filename '%s' is too long\n", FWname); 46 | uint8_t n8 = FWnameLen; 47 | 48 | // Open and check firmware file 49 | FILE *FW = fopen(argv[2], "r"); 50 | myassert(FW, 0x10, "Failed to open '%s' for reading\n", argv[2]); 51 | char buf[0x20]; 52 | myassert(1 == fread(buf, 7, 1, FW), 0x10, "Failed to read from '%s'\n", argv[2]); 53 | myassert(!memcmp(buf, BFL_FILE_MAGIC, sizeof(BFL_FILE_MAGIC)-1), 0x11, "'%s' doesn't look like a BFL firmware\n", argv[2]); 54 | myassert(!fseek(FW, 0, SEEK_END), 0x12, "Failed to find end of '%s'\n", argv[2]); 55 | long FWlen = ftell(FW); 56 | myassert(FWlen > 0, 0x12, "Couldn't get size of '%s'\n", argv[2]); 57 | myassert(!fseek(FW, 7, SEEK_SET), 0x12, "Failed to rewind firmware file after getting size\n"); 58 | FWlen -= 7; 59 | printf("Firmware file looks OK :)\n"); 60 | 61 | // Open device 62 | FILE *BFL = fopen(argv[1], "r+"); 63 | myassert(BFL, 0x20, "Failed to open '%s' for read/write\n", argv[1]); 64 | myassert(!setvbuf(BFL, NULL, _IOFBF, 1032), 0x21, "Failed to setup buffer for device"); 65 | 66 | // ZAX: Start firmware upload 67 | printf("Starting firmware upload... "); 68 | myassert(1 == fwrite("ZAX", 3, 1, BFL), 0x22, "Failed to issue ZAX command\n"); 69 | WAITFOROK(0x22, "ZAX"); 70 | 71 | // Firmware upload header 72 | myassert(1 == fwrite(BFL_UPLOAD_MAGIC, sizeof(BFL_UPLOAD_MAGIC)-1, 1, BFL), 0x23, "Failed to send firmware upload header (magic)\n"); 73 | uint32_t n32 = htonl(FWlen - FWlen / 6); 74 | myassert(1 == fwrite(&n32, sizeof(n32), 1, BFL), 0x23, "Failed to send firmware upload header (size)\n"); 75 | myassert(1 == fwrite("\0\0", 2 , 1, BFL), 0x23, "Failed to send firmware upload header (padding 1)\n"); 76 | myassert(1 == fwrite(&n8, sizeof(n8) , 1, BFL), 0x23, "Failed to send firmware upload header (filename length)\n"); 77 | myassert(1 == fwrite(FWname, n8 , 1, BFL), 0x23, "Failed to send firmware upload header (filename)\n"); 78 | myassert(1 == fwrite("\0>>>>>>>>", 9 , 1, BFL), 0x23, "Failed to send firmware upload header (padding 2)\n"); 79 | WAITFOROK(0x23, "firmware upload header"); 80 | printf("OK, sending...\n"); 81 | 82 | // Actual firmware upload 83 | long i, j; 84 | for (i = 0, j = 0; i < FWlen; ++i) { 85 | myassert(1 == fread(&n8, sizeof(n8), 1, FW), 0x30, "Error reading data from firmware file\n"); 86 | if (5 == i % 6) 87 | continue; 88 | n8 ^= 0x2f; 89 | myassert(1 == fwrite(&n8, sizeof(n8), 1, BFL), 0x31, "Error sending data to device\n"); 90 | if (!(++j % 0x400)) { 91 | myassert(1 == fwrite(">>>>>>>>", 8, 1, BFL), 0x32, "Error sending block-finish to device\n"); 92 | printf("\r%5.2f%% complete", (double)i * 100. / (double)FWlen); 93 | WAITFOROK(0x32, "block-finish"); 94 | } 95 | } 96 | printf("\r100%% complete :)\n"); 97 | myassert(1 == fwrite(">>>>>>>>", 8, 1, BFL), 0x3f, "Error sending upload-finished to device\n"); 98 | myassert(fgets(buf, sizeof(buf), BFL), 0x3f, "Error reading response from upload-finished\n"); 99 | myassert(!strcmp(buf, "DONE\n"), 0x3f, "Invalid response from upload-finished: %s%s", ERRRESP(buf)); 100 | 101 | // ZBX: Finish programming 102 | printf("Waiting for device... "); 103 | myassert(1 == fwrite("ZBX", 3, 1, BFL), 0x40, "Failed to issue ZBX command\n"); 104 | WAITFOROK(0x40, "ZBX"); 105 | printf("All done! Try mining to test the flash succeeded.\n"); 106 | 107 | return 0; 108 | } 109 | -------------------------------------------------------------------------------- /m4/extensions.m4: -------------------------------------------------------------------------------- 1 | # serial 9 -*- Autoconf -*- 2 | # Enable extensions on systems that normally disable them. 3 | 4 | # Copyright (C) 2003, 2006-2011 Free Software Foundation, Inc. 5 | # This file is free software; the Free Software Foundation 6 | # gives unlimited permission to copy and/or distribute it, 7 | # with or without modifications, as long as this notice is preserved. 8 | 9 | # This definition of AC_USE_SYSTEM_EXTENSIONS is stolen from CVS 10 | # Autoconf. Perhaps we can remove this once we can assume Autoconf 11 | # 2.62 or later everywhere, but since CVS Autoconf mutates rapidly 12 | # enough in this area it's likely we'll need to redefine 13 | # AC_USE_SYSTEM_EXTENSIONS for quite some time. 14 | 15 | # If autoconf reports a warning 16 | # warning: AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS 17 | # or warning: AC_RUN_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS 18 | # the fix is 19 | # 1) to ensure that AC_USE_SYSTEM_EXTENSIONS is never directly invoked 20 | # but always AC_REQUIREd, 21 | # 2) to ensure that for each occurrence of 22 | # AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) 23 | # or 24 | # AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) 25 | # the corresponding gnulib module description has 'extensions' among 26 | # its dependencies. This will ensure that the gl_USE_SYSTEM_EXTENSIONS 27 | # invocation occurs in gl_EARLY, not in gl_INIT. 28 | 29 | # AC_USE_SYSTEM_EXTENSIONS 30 | # ------------------------ 31 | # Enable extensions on systems that normally disable them, 32 | # typically due to standards-conformance issues. 33 | # Remember that #undef in AH_VERBATIM gets replaced with #define by 34 | # AC_DEFINE. The goal here is to define all known feature-enabling 35 | # macros, then, if reports of conflicts are made, disable macros that 36 | # cause problems on some platforms (such as __EXTENSIONS__). 37 | AC_DEFUN_ONCE([AC_USE_SYSTEM_EXTENSIONS], 38 | [AC_BEFORE([$0], [AC_COMPILE_IFELSE])dnl 39 | AC_BEFORE([$0], [AC_RUN_IFELSE])dnl 40 | 41 | AC_REQUIRE([AC_CANONICAL_HOST]) 42 | 43 | AC_CHECK_HEADER([minix/config.h], [MINIX=yes], [MINIX=]) 44 | if test "$MINIX" = yes; then 45 | AC_DEFINE([_POSIX_SOURCE], [1], 46 | [Define to 1 if you need to in order for `stat' and other 47 | things to work.]) 48 | AC_DEFINE([_POSIX_1_SOURCE], [2], 49 | [Define to 2 if the system does not provide POSIX.1 features 50 | except with this defined.]) 51 | AC_DEFINE([_MINIX], [1], 52 | [Define to 1 if on MINIX.]) 53 | fi 54 | 55 | dnl HP-UX 11.11 defines mbstate_t only if _XOPEN_SOURCE is defined to 500, 56 | dnl regardless of whether the flags -Ae or _D_HPUX_SOURCE=1 are already 57 | dnl provided. 58 | case "$host_os" in 59 | hpux*) 60 | AC_DEFINE([_XOPEN_SOURCE], [500], 61 | [Define to 500 only on HP-UX.]) 62 | ;; 63 | esac 64 | 65 | AH_VERBATIM([__EXTENSIONS__], 66 | [/* Enable extensions on AIX 3, Interix. */ 67 | #ifndef _ALL_SOURCE 68 | # undef _ALL_SOURCE 69 | #endif 70 | /* Enable GNU extensions on systems that have them. */ 71 | #ifndef _GNU_SOURCE 72 | # undef _GNU_SOURCE 73 | #endif 74 | /* Enable threading extensions on Solaris. */ 75 | #ifndef _POSIX_PTHREAD_SEMANTICS 76 | # undef _POSIX_PTHREAD_SEMANTICS 77 | #endif 78 | /* Enable extensions on HP NonStop. */ 79 | #ifndef _TANDEM_SOURCE 80 | # undef _TANDEM_SOURCE 81 | #endif 82 | /* Enable general extensions on Solaris. */ 83 | #ifndef __EXTENSIONS__ 84 | # undef __EXTENSIONS__ 85 | #endif 86 | ]) 87 | AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__], 88 | [ac_cv_safe_to_define___extensions__], 89 | [AC_COMPILE_IFELSE( 90 | [AC_LANG_PROGRAM([[ 91 | # define __EXTENSIONS__ 1 92 | ]AC_INCLUDES_DEFAULT])], 93 | [ac_cv_safe_to_define___extensions__=yes], 94 | [ac_cv_safe_to_define___extensions__=no])]) 95 | test $ac_cv_safe_to_define___extensions__ = yes && 96 | AC_DEFINE([__EXTENSIONS__]) 97 | AC_DEFINE([_ALL_SOURCE]) 98 | AC_DEFINE([_GNU_SOURCE]) 99 | AC_DEFINE([_POSIX_PTHREAD_SEMANTICS]) 100 | AC_DEFINE([_TANDEM_SOURCE]) 101 | ])# AC_USE_SYSTEM_EXTENSIONS 102 | 103 | # gl_USE_SYSTEM_EXTENSIONS 104 | # ------------------------ 105 | # Enable extensions on systems that normally disable them, 106 | # typically due to standards-conformance issues. 107 | AC_DEFUN_ONCE([gl_USE_SYSTEM_EXTENSIONS], 108 | [ 109 | dnl Require this macro before AC_USE_SYSTEM_EXTENSIONS. 110 | dnl gnulib does not need it. But if it gets required by third-party macros 111 | dnl after AC_USE_SYSTEM_EXTENSIONS is required, autoconf 2.62..2.63 emit a 112 | dnl warning: "AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS". 113 | dnl Note: We can do this only for one of the macros AC_AIX, AC_GNU_SOURCE, 114 | dnl AC_MINIX. If people still use AC_AIX or AC_MINIX, they are out of luck. 115 | AC_REQUIRE([AC_GNU_SOURCE]) 116 | 117 | AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) 118 | ]) 119 | -------------------------------------------------------------------------------- /compat/jansson-2.5/src/utf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2013 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #include 9 | #include "utf.h" 10 | 11 | int utf8_encode(int32_t codepoint, char *buffer, int *size) 12 | { 13 | if(codepoint < 0) 14 | return -1; 15 | else if(codepoint < 0x80) 16 | { 17 | buffer[0] = (char)codepoint; 18 | *size = 1; 19 | } 20 | else if(codepoint < 0x800) 21 | { 22 | buffer[0] = 0xC0 + ((codepoint & 0x7C0) >> 6); 23 | buffer[1] = 0x80 + ((codepoint & 0x03F)); 24 | *size = 2; 25 | } 26 | else if(codepoint < 0x10000) 27 | { 28 | buffer[0] = 0xE0 + ((codepoint & 0xF000) >> 12); 29 | buffer[1] = 0x80 + ((codepoint & 0x0FC0) >> 6); 30 | buffer[2] = 0x80 + ((codepoint & 0x003F)); 31 | *size = 3; 32 | } 33 | else if(codepoint <= 0x10FFFF) 34 | { 35 | buffer[0] = 0xF0 + ((codepoint & 0x1C0000) >> 18); 36 | buffer[1] = 0x80 + ((codepoint & 0x03F000) >> 12); 37 | buffer[2] = 0x80 + ((codepoint & 0x000FC0) >> 6); 38 | buffer[3] = 0x80 + ((codepoint & 0x00003F)); 39 | *size = 4; 40 | } 41 | else 42 | return -1; 43 | 44 | return 0; 45 | } 46 | 47 | int utf8_check_first(char byte) 48 | { 49 | unsigned char u = (unsigned char)byte; 50 | 51 | if(u < 0x80) 52 | return 1; 53 | 54 | if(0x80 <= u && u <= 0xBF) { 55 | /* second, third or fourth byte of a multi-byte 56 | sequence, i.e. a "continuation byte" */ 57 | return 0; 58 | } 59 | else if(u == 0xC0 || u == 0xC1) { 60 | /* overlong encoding of an ASCII byte */ 61 | return 0; 62 | } 63 | else if(0xC2 <= u && u <= 0xDF) { 64 | /* 2-byte sequence */ 65 | return 2; 66 | } 67 | 68 | else if(0xE0 <= u && u <= 0xEF) { 69 | /* 3-byte sequence */ 70 | return 3; 71 | } 72 | else if(0xF0 <= u && u <= 0xF4) { 73 | /* 4-byte sequence */ 74 | return 4; 75 | } 76 | else { /* u >= 0xF5 */ 77 | /* Restricted (start of 4-, 5- or 6-byte sequence) or invalid 78 | UTF-8 */ 79 | return 0; 80 | } 81 | } 82 | 83 | int utf8_check_full(const char *buffer, int size, int32_t *codepoint) 84 | { 85 | int i; 86 | int32_t value = 0; 87 | unsigned char u = (unsigned char)buffer[0]; 88 | 89 | if(size == 2) 90 | { 91 | value = u & 0x1F; 92 | } 93 | else if(size == 3) 94 | { 95 | value = u & 0xF; 96 | } 97 | else if(size == 4) 98 | { 99 | value = u & 0x7; 100 | } 101 | else 102 | return 0; 103 | 104 | for(i = 1; i < size; i++) 105 | { 106 | u = (unsigned char)buffer[i]; 107 | 108 | if(u < 0x80 || u > 0xBF) { 109 | /* not a continuation byte */ 110 | return 0; 111 | } 112 | 113 | value = (value << 6) + (u & 0x3F); 114 | } 115 | 116 | if(value > 0x10FFFF) { 117 | /* not in Unicode range */ 118 | return 0; 119 | } 120 | 121 | else if(0xD800 <= value && value <= 0xDFFF) { 122 | /* invalid code point (UTF-16 surrogate halves) */ 123 | return 0; 124 | } 125 | 126 | else if((size == 2 && value < 0x80) || 127 | (size == 3 && value < 0x800) || 128 | (size == 4 && value < 0x10000)) { 129 | /* overlong encoding */ 130 | return 0; 131 | } 132 | 133 | if(codepoint) 134 | *codepoint = value; 135 | 136 | return 1; 137 | } 138 | 139 | const char *utf8_iterate(const char *buffer, int32_t *codepoint) 140 | { 141 | int count; 142 | int32_t value; 143 | 144 | if(!*buffer) 145 | return buffer; 146 | 147 | count = utf8_check_first(buffer[0]); 148 | if(count <= 0) 149 | return NULL; 150 | 151 | if(count == 1) 152 | value = (unsigned char)buffer[0]; 153 | else 154 | { 155 | if(!utf8_check_full(buffer, count, &value)) 156 | return NULL; 157 | } 158 | 159 | if(codepoint) 160 | *codepoint = value; 161 | 162 | return buffer + count; 163 | } 164 | 165 | int utf8_check_string(const char *string, int length) 166 | { 167 | int i; 168 | 169 | if(length == -1) 170 | length = strlen(string); 171 | 172 | for(i = 0; i < length; i++) 173 | { 174 | int count = utf8_check_first(string[i]); 175 | if(count == 0) 176 | return 0; 177 | else if(count > 1) 178 | { 179 | if(i + count > length) 180 | return 0; 181 | 182 | if(!utf8_check_full(&string[i], count, NULL)) 183 | return 0; 184 | 185 | i += count - 1; 186 | } 187 | } 188 | 189 | return 1; 190 | } 191 | --------------------------------------------------------------------------------