This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v2 11/17] introduce relative_filename and use it


>>>>> "Doug" == Doug Evans <dje@google.com> writes:

Doug> There's also string compare -length.

Doug> Or maybe for some incremental robustness, do the file splits first and
Doug> then compare that?

Ok, I replaced it with this implementation.
Let me know what you think.


proc relative_filename {root full} {
    set root_split [file split $root]
    set full_split [file split $full]

    set len [llength $root_split]

    if {[eval file join $root_split]
	!= [eval file join [lrange $full_split 0 [expr {$len - 1}]]]} {
	error "$full not a subdir of $root"
    }

    return [eval file join [lrange $full_split $len end]]
}

Tom


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]