Skip to main content
1 of 4
vnp
  • 57.3k
  • 4
  • 51
  • 140
  • mutex serves no purpose. It is not shared between processes, and your program is not multithreaded.

    If you want an exclusion between unrelated instances of the program, you need to place it in a named shared memory segment (see example).

  • // Don't need any semaphores here - writing processes write to a temp file then rename so no issues with reading

    Not so. Process P1 writes to temp1. Meanwhile, process P2 writes to temp2. After renaming, one of the edits is lost.

  • The line

      index = fopen("index.bin", "r");
    

    at the end of addIndexLine has no effect. The caller still has the original file pointer. BTW, after the call to addIndexLin the pointed file is closed, and cannot be used by a caller anymore. Doesn't look promising.

  • remove("data.bin") is superfluous. Just rename works as well.

  • Don't spell out the program name in the help/error messages. Use argv[0].

  • const-qualification of arguments is sorely missing.

  • Don't spell out the program name in the help/error messages. Use argv[0].

  • compareString... What's wrong with strncmp?

vnp
  • 57.3k
  • 4
  • 51
  • 140