A federal judge has upheld a South Carolina law allowing police to check people's immigration status.