12. The supreme court issues the writ by virtue of its appellate jurisdiction, 4 Cranch, 75 ; and it will not grant it at the instance of the subject of a foreign government to ob tain the custody of a minor child detained by a citizen of one of the states ; for that would be the exercise of original jurisdiction. 2 How. 65.
It will grant it on the application of one committed for trial in the circuit court on a criminal charge, 4 Cranch, 75 ; 3 Dall. 17 ; and where the petitioner is committed on an insufficient warrant, 3 Cranch, 448 ; and where he is detained by the marshal on a capias ad satisfaciendum after the return day of the writ. 7 Pet. 568.
13. None of the courts of the United States have authority to grant the writ for the pur pose of inquiring into the cause of commit ment, where the prisoner is imprisoned under process issued from' the state courts. It was refused by the supreme court where the party for whose benefit the application was made had been convicted in a state court of levying war against the state. 3 How. 103.
It was refused by the circuit court where the petitioner, a secretary • attached to the Spanish legation, was confined under crimi nal process issued under the authority of the state of Pennsylvania, 1 Wash. C. C. 232 ; also where the petitioner, a British seaman, was arrested under the authority of an act of the legislature of the state of South Caro rolina, which was held to conflict with the constitution of the United States. 2 Wheel. Cr. Cas. N. Y. 56.
It will be granted, however, where the im prisonment, although by a state officer, is under or by color of the authority of the United States, as where the prisoner was ar rested under a governor's warrant as it fu gitive from justice of another state, requisi tion having been regularly made. 3 McLean, C. C. 121.
14. Proper use of the writ. The true use of the writ is to cause a legal inquiry into the cause of imprisonment, and to procure the release of the prisoner where that is found to be illegal.
If the imprisonment be claimed by virtue of legal process, the validity and present force of such process are the only subjects of investigation. 5 Hill, N.Y. 164 ; 4 Barb. N.Y.
31 ; 4 Harr. Del. 575 ; Hurd, Hab. Corp. 332.
But such process cannot, in this proceed ing, be invalidated by errors which only.ren der it irregular. The defects, to entitle the prisoner to be discharged, must be such as to render the process void ; for the writ of habeas corpus is not, and cannot perform the office of, a writ of error. 3 Vt. 114 ; 6 id. 509 ; 4 Day, Conn. 436 ; 3 Hawks. No. C. 25 ; 2 La. 422, 587 : 8 id. 185 ; 2 Park. Crim. N. Y. 650; 1 Hill, N. Y. 154 ; 1 Abb. Pract. Cas. N. Y. 210 ; 11 How. Pract. N. Y. 418 ; 4 Carr. & P. 415; 7 Ohio St. 81 ; Hurd. Hab. Corp. 334.
It cannot be used to oust another compe tent and acting jurisdiction, or to divert or de feat the course of justice therein. 5 Ark. 424; 1 111.198 ; 16 Ohio, 405 ; 1 Md. Ch. Dec. 351; 2 id. 42 ; 19 Ala. N. s. 438 ; 6Ala. 9: 2Wheat. 532 ; 3 Yerg. Tenn. 167 ; 1 Edw. Ch. N.Y. 551 ; 1 Harr. Del. 392 ; 2 Aik. Vt. 381 ; 6 Miss. 80 ; 1 Curt. C. C. 178„- 2 Green, N. J. 312 ; 4 M•Cord, So. C. ; 1 Watts, Penn. 66 ; 6 McLean, C. C. 355 ; 10 Pick. Mass. 434 ; 7 Cush. Mass. 285 ; 8 Ohio St. 599 ; 21 How. 506 ; Hurd, Hab. Corp. 335.
15. The writ is also employed to recover the custody of a person where the applicant has a legal right thereto: as, the husband for his wife, the parent for his child, the guard ian for his ward, and the master for his apprentice. But in such cases, as the just object of the proceeding is rather to remove illegal restraint than to enforce specifically the claims of private custody, the alleged prisoner, if an adult of sound mind, is gene rally permitted to go at large ; if an infant of sufficient age and discretion, it is usually permitted to elect in whose custody it will remain, provided that it does not elect an injurious or improper custody : and if of ten der years, without such discretion, the court determines its custody according to what the true interests and welfare of the child may at the time require. Hurd, Hab. Corp. 450— 551.
16. Application for the writ. This may be made by the prisoner, or by any one on his behalf, where for any reason he is unable to make it.