bootstrap.c 751 B

123456789101112131415161718192021222324252627
  1. #include <stdio.h>
  2. #include <string.h>
  3. int main(int argc, const char** argv, const char** envp) {
  4. printf("User Program Started\n");
  5. printf("# of Arguments: %d\n", argc);
  6. for (int i = 0; i < argc; i++) {
  7. printf("argv[%d] = %s\n", i, argv[i]);
  8. }
  9. /* Make sure argv strings follow the compact encoding where (1) all strings
  10. are located adjacently and (2) in increasing order. */
  11. size_t sum_len = 0;
  12. for (int i = 0; i < argc; i++) {
  13. sum_len += strlen(argv[i]) + 1;
  14. }
  15. size_t chunk_len = argv[argc - 1] + strlen(argv[argc - 1]) - argv[0];
  16. if (sum_len != chunk_len + 1) {
  17. printf("argv strings are not adjacent or not in increasing order\n");
  18. return 1;
  19. }
  20. return 0;
  21. }