title: How does ls sort filenames?
body: <p>I'm trying to write a function that mimics the output of the ls command in Unix. I was originally trying to perform this using scandir and alphasort, and this did indeed print the files in the directory, and it did sort them, but for some reason, this sorted list does not seem to match the same "sorted list" of filenames that ls gives. </p>
  
  <p>For example, if I have a directory that contains file.c, FILE.c, and ls.c.</p>
  
  <p>ls displays them in the order: file.c FILE.c ls.c
  But when I sort it using alphasort/scandir, it sorts them as: FILE.c file.c ls.c</p>
  
  <p>How does ls sort the files in the directory such that it gives such a differently ordered result?</p>