It is best illustrated with the following Go code snippet.
var x int| #ifndef PRINTHEX_H | |
| #define PRINTHEX_H | |
| #include <stdio.h> | |
| // Display data in hexadecimal | |
| inline void printHex( const void* data, size_t len, const char* margin ) | |
| { | |
| if( len == 0 ) | |
| { |
| #include <cmath> | |
| //! One kibibyte unit size (see http://en.wikipedia.org/wiki/Kibibyte) | |
| const size_t KiB = 1024; | |
| //! One mebibyte unit size (see http://en.wikipedia.org/wiki/Mebibyte) | |
| const size_t MiB = 1024*1024; | |
| //! Convert timeval structure to a double | |
| double toDbl( struct timeval& t ) |
| #include <sys/time.h> | |
| // Return the current time as a double float in second units | |
| double getTimeAsDouble() | |
| { | |
| struct timeval t; | |
| ::gettimeofday( &t, NULL ); | |
| return double(t.tv_sec) + double(t.tv_usec)/1000000.0; | |
| } |
| // Please use the package https://github.com/chmike/domain as is it maintained up to date with tests. | |
| // checkDomain returns an error if the domain name is not valid. | |
| // See https://tools.ietf.org/html/rfc1034#section-3.5 and | |
| // https://tools.ietf.org/html/rfc1123#section-2. | |
| func checkDomain(name string) error { | |
| switch { | |
| case len(name) == 0: | |
| return nil // an empty domain name will result in a cookie without a domain restriction | |
| case len(name) > 255: |
| func dumpByteSlice(b []byte) { | |
| var a [16]byte | |
| n := (len(b) + 15) &^ 15 | |
| for i := 0; i < n; i++ { | |
| if i%16 == 0 { | |
| fmt.Printf("%4d", i) | |
| } | |
| if i%8 == 0 { | |
| fmt.Print(" ") | |
| } |
| var ( | |
| cnNameOid = asn1.ObjectIdentifier{2, 5, 4, 3} | |
| emailOid = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 1} | |
| userIDOid = asn1.ObjectIdentifier{0, 9, 2342, 19200300, 100, 1, 1} | |
| dcNameOid = asn1.ObjectIdentifier{0, 9, 2342, 19200300, 100, 1, 25} | |
| ) | |
| // RDNSToString returns the Relative Distinguish Name as a string. | |
| func RDNSToString(rdns *pkix.RDNSequence) string { | |
| var buf strings.Builder |
| res, err := http.GET(...) | |
| if res != nil { | |
| defer func() { | |
| _, err = io.Copy(ioutil.Discard, res.Body) | |
| res.Body.Close() | |
| }() | |
| } | |
| if err != nil { | |
| // . . . | |
| } |
| // getlinefd reads a full line from fd into *lineptr. Initialize *lineptr to NULL and *n to 0. | |
| // getlinefd will store the line into *lineptr which is is a buffer that will grow as needed. | |
| // The buffer size is stored in *n. The line ends '\0' and with a '\n'when present. | |
| // getlinefd returns the number of characters read, or -1 in case of error or if the end of file is reached. | |
| ssize_t getlinefd(char **lineptr, size_t *n, int fd) { | |
| static char buf[10]; | |
| static size_t len = 0; | |
| const size_t blen = sizeof(buf); | |
| if (lineptr == NULL || n == NULL) { |
| package main | |
| import ( | |
| "fmt" | |
| "image" | |
| "image/color" | |
| "os" | |
| "gioui.org/app" | |
| "gioui.org/font/gofont" |