Pascal, 224 B
This complete Pascal program requires a processor meeting the requirements of ISO standard 7185 “Standard Pascal” or ISO standard 10206 “Extended Pascal”.
program X(A,B);var A,B,C:text;Z:char;procedure M(var S,D:text);begin reset(S);rewrite(D);while not EOF(S) do begin while not EOLn(S) do begin read(S,Z);write(D,Z)end;readLn(S);writeLn(D)end end;begin M(A,C);M(B,A);M(C,B)end.
The notion of files being organized in a file system is foreign to Pascal so renaming files is not an option. Commented:
program swap(A, B); var A, B, C: text; procedure copy(var source, destination: text); var buffer: char; begin reset(source); rewrite(destination); while not EOF(source) do begin { A `text` file is a (possibly empty) sequence of lines. Each line is a (possibly empty) sequence of `char` values followed by one implementation‐defined end‐of‐line sequence. } while not EOLn(source) do begin read(source, buffer); write(destination, buffer) end; { `Read` can (by design) not read across lines. } readLn(source); { Upon reaching the end of a line, the file buffer `source↑` returns the `char` value of a space character. Therefore, in Pascal the only correct method of emitting an end‐of‐line character sequence is `writeLn`. } writeLn(destination) end end; begin copy(A, C); { original A = C } copy(B, A); { original B = new A } copy(C, B) { C = original A = new B } end.
Note that the method of associating program parameters with external entities is implementation‐defined. For example the GNU Pascal Compiler prompts you for pathnames when reset or rewrite are invoked for the first time:
Input file `A': i.txt Input file `B': o.txt
The i.txt and o.txt are user input (i. e. not generated by the program) and only program parameters are queried in this fashion (so not C).
The FreePascal Compiler in its (not yet mature) ISO compiler compatibility mode, on the other hand, expects pathnames as command‐line arguments. However, as of version 3.2.4 the FreePascal Compiler does not support anonymous files; the text file C is not associated with a pathname and the FPC cannot deal with that (fails miserably).
inodes the goal here would be fori.txt'sinodeto contain the data fromo.txt'sinode, and vice versa, so that if there are hardlinks to thoseinodes elsewhere, their contents will appear swapped as well. Renaming can't accomplish that. \$\endgroup\$