- char buf[1024];
- size_t len;
- while((len = fread(buf, 1, sizeof(buf), in)))
- fwrite(buf, len, 1, out);
+ char line[1024];
+
+ while(fgets(line, sizeof(line), in)) {
+ const char *var_beg = line + strspn(line, "\t ");
+ const char *var_end = var_beg + strcspn(var_beg, "\t ");
+
+ // Check the name of the variable we've read. If it's Port, replace it with
+ // a port we'll use in invitation URL. Otherwise, just copy the line.
+ if(var_end > var_beg && !strncasecmp(var_beg, "Port", var_end - var_beg)) {
+ fprintf(out, "Port = %s\n", port);
+ } else {
+ fprintf(out, "%s", line);
+ }
+ }
+
+ memzero(line, sizeof(line));