<div dir="ltr"><p><font face="Courier">When doing the HW, my function's option is </font>open(dst, O_WRONLY | O_CREAT | O_TRUNC, src_st.st_mode), it works fine when I copy a executable shell script. </p>
<p>But when I chmod 777 to the source script and use program to copy,
the target file's permission remains "-rwxr-xr-x". This is where this
problem from.</p><p><br></p><p>if the file already exist, /bin/cp will keep its original permissions,</p><p>According the specification of open(2):</p><p> the third parameter is used to mode specifies the permissions to use in case a *new* file is created. </p>
<p><br></p><p>-Hao<br></p></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Sep 14, 2013 at 12:33 AM, Hongyi Shen <span dir="ltr"><<a href="mailto:hshen4@stevens.edu" target="_blank">hshen4@stevens.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">
                
        
        
                <div title="Page 79">
                        <div>
                                <div>
                                        <div>
                                                <p><font face="Courier">In open() function:</font></p><p><span style="font-size:10pt;font-family:Courier">int open(const char *pathname, int oflag, ... /* mode_t mode */ ); </span></p><p><span style="font-size:10pt;font-family:Courier"><br>
</span></p><p><font face="Courier">Both <i>oflag</i> and <i>mode could </i>control the file's permission. So both of them call stat() inside? </font></p><p><font face="Courier"><b><font size="4">Question: What if they are conflict with each other? (like O_RDONLY and mode 0777 together)</font></b></font></p>
<p><font face="Courier"><br></font></p><p><font face="Courier">When doing the HW, my function's option is </font>open(dst, O_WRONLY | O_CREAT | O_TRUNC, src_st.st_mode), it works fine when I copy a executable shell script. </p>
<p>But when I chmod 777 to the source script and use program to copy, the target file's permission remains "-rwxr-xr-x". This is where this problem from.</p><p><br></p><p><font face="Courier"> </font></p>
                                        </div>
                                </div>
                        </div>
                </div></div>
<br>_______________________________________________<br>
cs631apue mailing list<br>
<a href="mailto:cs631apue@lists.stevens.edu">cs631apue@lists.stevens.edu</a><br>
<a href="https://lists.stevens.edu/mailman/listinfo/cs631apue" target="_blank">https://lists.stevens.edu/mailman/listinfo/cs631apue</a><br>
<br></blockquote></div><br></div>