0
+ − 1 /*
+ − 2 Copyright (c) 2014 Erik Mackdanz <erikmack@gmail.com>
+ − 3
+ − 4 Permission to use, copy, modify, and distribute this software for any
+ − 5 purpose with or without fee is hereby granted, provided that the above
+ − 6 copyright notice and this permission notice appear in all copies.
+ − 7
+ − 8 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ − 9 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ − 10 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ − 11 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ − 12 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ − 13 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ − 14 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ − 15 */
+ − 16
+ − 17 #include <stdlib.h>
+ − 18 #include <stdio.h>
+ − 19
+ − 20 char get_next_char(char in) {
+ − 21 return in+1;
+ − 22 }
+ − 23
+ − 24 unsigned char get_next_char_u(unsigned char in) {
+ − 25 /* printf("In c, sum is %d\n",in+1); */
+ − 26 return in+1;
+ − 27 }
+ − 28
+ − 29 int is_false(int in) {
+ − 30 return !in;
+ − 31 }
+ − 32
+ − 33 unsigned int dual_increment_u(unsigned int in) {
+ − 34 in++;
+ − 35 in++;
+ − 36 return in;
+ − 37 }
+ − 38
+ − 39 short times_three(short in) {
+ − 40 return in * 3;
+ − 41 }
+ − 42
+ − 43 unsigned short times_three_u(unsigned short in) {
+ − 44 return in * 3;
+ − 45 }
+ − 46
+ − 47 long add_nineteen(long in) {
+ − 48 return in + 19;
+ − 49 }
+ − 50
+ − 51 unsigned long add_nineteen_u(unsigned long in) {
+ − 52 return in + 19;
+ − 53 }
+ − 54
+ − 55 long long subtract_four(long long in) {
+ − 56 return in - 4;
+ − 57 }
+ − 58
+ − 59 unsigned long long subtract_four_u(unsigned long long in) {
+ − 60 return in - 4;
+ − 61 }
+ − 62
+ − 63 int add_seven(int in) {
+ − 64 return in + 7;
+ − 65 }
+ − 66
+ − 67 int add_one(int in) {
+ − 68 return in + 1;
+ − 69 }
+ − 70
+ − 71 void* coolmalloc(int sz) {
+ − 72 void* ptr = malloc(sz);
+ − 73 /* printf("I've allocated at addr %p\n",ptr); */
+ − 74 return ptr;
+ − 75 }
+ − 76
+ − 77 void* coolidentity(void* in) {
+ − 78 return in;
+ − 79 }
+ − 80
+ − 81 void coolsetstr(void* buf, char* val) {
+ − 82 sprintf(buf,"%s",val);
+ − 83 }
+ − 84
+ − 85 void coolfree(void* ptr) {
+ − 86 /* printf("The value to free is %s\n", ptr); */
+ − 87 free(ptr);
+ − 88 }
+ − 89
+ − 90 void noop() {}
+ − 91
+ − 92 float calculate_pi(float precision) {
+ − 93 return 21.0 / (7.0 * precision); // closer...
+ − 94 }
+ − 95
+ − 96 double times_pi(double multiplicand) {
+ − 97 return multiplicand * 3.1; // nerd rage!
+ − 98 }
+ − 99
+ − 100 char* interested_reply(char* yourname) {
+ − 101 int totalmax = 256;
+ − 102 char* buf = malloc(totalmax);
+ − 103 snprintf(buf,totalmax,"Really, %s? My name is Erik.",yourname);
+ − 104 return buf;
+ − 105 }
+ − 106
+ − 107 char* several_args(long one, char two, char* three, float four) {
+ − 108 char* reply = malloc(100);
+ − 109 snprintf(reply, 100,"Your args were %ld, %c, %s, %.1f",
+ − 110 one,two,three,four);
+ − 111 return reply;
+ − 112 }