Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Problem : having one file created on the current dir, want to create it on /tmp
- Solution : prepend « /tmp/ » to the filename, without breaking some other code part…
- Language 1 : Java, 10ms
- Before :
- String filename;
- … some code to calculate the filename …
- File file = new File(filename);
- After :
- String filename;
- … some code to calculate the filename …
- File file = new File("/tmp/" + filename); # Or better, new File("/tmp", filename) !
- Langage 2 : C, 10min
- Before :
- char filename[255];
- … some code to calculate the filename …
- FILE *file = fopen(filename, "rb");
- After :
- char filename[255];
- … some code to calculate the filename …
- File *file = fopen(filename, "rb");
- char tmp[255]; # Sniff, hardcoded length, and one useless variable :(…
- strcat(tmp, "/tmp/");
- strcat(tmp, filename);
- strcpy(filename, tmp);
- FILE *file = fopen(filename, "rb");
- No comment…
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement