The only way to do an in-place edit is to change bytes in the file on a one-for-one basis. One option is to work it like perl's -i cli switch and move the old file to a new filename (httpd.conf.bak), then open the old/original filename (httpd.conf) as a new file. Open the backup for reading and print line-by-line into the new file until you get to the point you want to insert text, insert, and continue to append the backup file. Delete the backup when the script finishes.
----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light