title: Creating pointer to first char in File object
body: <p>I am trying to replicate the C stdio library using Unix system calls. To start, I am trying to mimic/recreate <code>fopen</code> using only the <code>open</code> UNIX system call.</p>
  <p>I have a File class where I want the constructor to open a file that I pass to the constructor in a mode that I also pass in. I want to create a pointer to the first byte in the file that I have opened using <code>open</code>, but am unsure of how to do this. In the file class, I have a private member <code>char* curPtr</code>, which I would like to use to represent the current location of where I am in a file (when reading or writing, which I will use further down the line).</p>
  <p>I do not know how to &quot;link&quot; the file descriptor that is returned from <code>open</code> with the <code>curPtr</code> data member. I currently have some code implemented below which is basically type casting the file descriptor, which is an int, to a char* (Like this: <code>curPtr = (char*)fileDescriptor;</code>), but I dont know if this is correct. I want to use <code>curPtr*</code> to index through the file byte by byte I have opened and be able to print out or write individual characters at the location to pointed at by <code>curPtr*</code>.</p>
  <p><strong>File Class:</strong></p>
  <pre><code>class File {
  public:
    class File_Exception: public std::exception {
    };
    static const int bufsiz = 8192;
    static const int eof = -1;
  
    File(const char *name, const char *mode = &quot;r&quot;);
  
    // Close the file.  Make sure any buffered data is written to disk,
    // and free the buffer if there is one.
    ~File();
  
    int fgetc();
    int fputc(int c);
  
  private:
    const char* fileName;         //stores the pointer to our file.
    int fileMode;           //stores our file mode.
    char* fileBuffer;       //Buffer
  
    char* curPtr;       //I want to use this pointer to point to the current location we are in a file.
  
    int fileDescriptor;   //The file descriptor for this particular file object.
  
    bool canWeRead = false;     //flag to indicate if we have read access
    bool canWeWrite = false;    //flag to indicate if we have write access
  
    int errorState = 0;     //0 indicates we have no errors. 1 indicates error
  
  };
  </code></pre>
  <p><strong>File Class Constructor</strong></p>
  <pre><code>File::File(const char *name, const char *mode) {
    int fileMode = 0;    //Initializing mode to 0
  
    fileName = name;    //Setting the file name of this File object to the name we pass in.
  
    switch(*mode){
      case 'r':
        fileMode = O_RDONLY | O_CREAT;
        canWeRead = true;
        canWeWrite = false;
        break;
      case 'r+':            
        fileMode = O_RDWR | O_CREAT;
        canWeRead = true;
        canWeWrite = true;
        break;
      case 'w':
        fileMode = O_WRONLY | O_CREAT;
        canWeRead = false;
        canWeWrite = true;
        break;
      case 'w+':           
        fileMode = O_RDWR | O_CREAT | O_TRUNC;
        canWeRead = true;
        canWeWrite = true;
        break;
      
      default:    //We should never reach the default case, so I assert(0)
        assert(0);
    }
  
    fileDescriptor = open(name, fileMode);
    assert(fileDescriptor &gt;= 0);    //If we dont get a positive nonnegative int, we have a problem.
  
    //How do I set the value of curPtr to the first char in my File object?
     curPtr = (char*)fileDescriptor; //I think that this works?
  }
  </code></pre>