Theory of the current-voltage characteristics of SNS junctions and other superconducting weak links