Skip to content

Commit

Permalink
get started on homework11
Browse files Browse the repository at this point in the history
  • Loading branch information
lemorage committed Oct 19, 2023
1 parent f0264c5 commit 5cf0719
Show file tree
Hide file tree
Showing 7 changed files with 1,546 additions and 0 deletions.
Empty file added hw11/README.md
Empty file.
22 changes: 22 additions & 0 deletions hw11/tiny/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
CC = gcc
CFLAGS = -O2 -Wall -I .

# This flag includes the Pthreads library on a Linux box.
# Others systems will probably require something different.
LIB = -lpthread

all: tiny cgi

tiny: tiny.c csapp.o
$(CC) $(CFLAGS) -o tiny tiny.c csapp.o $(LIB)

csapp.o: csapp.c
$(CC) $(CFLAGS) -c csapp.c

cgi:
(cd cgi-bin; make)

clean:
rm -f *.o tiny *~
(cd cgi-bin; make clean)

10 changes: 10 additions & 0 deletions hw11/tiny/cgi-bin/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CC = gcc
CFLAGS = -O2 -Wall -I ..

all: adder

adder: adder.c
$(CC) $(CFLAGS) -o adder adder.c

clean:
rm -f adder *~
38 changes: 38 additions & 0 deletions hw11/tiny/cgi-bin/adder.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* adder.c - a minimal CGI program that adds two numbers together
*/
/* $begin adder */
#include "csapp.h"

int main(void) {
char *buf, *p;
char arg1[MAXLINE], arg2[MAXLINE], content[MAXLINE];
int n1=0, n2=0;

/* Extract the two arguments */
if ((buf = getenv("QUERY_STRING")) != NULL) {
p = strchr(buf, '&');
*p = '\0';
strcpy(arg1, buf);
strcpy(arg2, p+1);
n1 = atoi(arg1);
n2 = atoi(arg2);
}

/* Make the response body */
sprintf(content, "Welcome to add.com: ");
sprintf(content, "%sTHE Internet addition portal.\r\n<p>", content);
sprintf(content, "%sThe answer is: %d + %d = %d\r\n<p>",
content, n1, n2, n1 + n2);
sprintf(content, "%sThanks for visiting!\r\n", content);

/* Generate the HTTP response */
printf("Connection: close\r\n");
printf("Content-length: %d\r\n", (int)strlen(content));
printf("Content-type: text/html\r\n\r\n");
printf("%s", content);
fflush(stdout);

exit(0);
}
/* $end adder */
Loading

0 comments on commit 5cf0719

Please sign in to comment.